Bonjour à tous,
Je reste perplexe devant un problème relativement simple...
Je voudrais comprendre pourquoi les 2 blocs d'instructions ci dessous n'ont pas le même comportment :
1er bloc : il a un comportement "normal" (je comprend ce qu'il fait et je suis d'accord)
2ème bloc (je ne comprends pas pourquoi ça plante) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 BEGIN BEGIN TRAN; DECLARE @a int declare @b int BEGIN TRY set @a=1/1 BEGIN TRY set @b=1/0 END TRY BEGIN CATCH PRINT 'Erreur CATCH 2 ' + ERROR_MESSAGE(); END CATCH END TRY BEGIN CATCH ROLLBACK; PRINT 'Erreur CATCH 1 ' + ERROR_MESSAGE(); END CATCH IF XACT_STATE() = 1 COMMIT; END
La seule différence entre les 2 blocs, c'est la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 BEGIN BEGIN TRAN; DECLARE @a int declare @b int BEGIN TRY set @a=1/1 BEGIN TRY set @b=cast('1A' as int) END TRY BEGIN CATCH PRINT 'Erreur CATCH 2 ' + ERROR_MESSAGE(); END CATCH END TRY BEGIN CATCH ROLLBACK; PRINT 'Erreur CATCH 1 ' + ERROR_MESSAGE(); END CATCH IF XACT_STATE() = 1 COMMIT; END
set @b=1/0
changée en
set @b=cast('1A' as int)
J'ai bien cherché sur le net, mais sans succès....
si quelqu'un pouvais éclairer ma lanterne...
Merci d'avance
Seb
Partager