If there is some situation arises to create more than one try-catch block and transaction, should be careful while throwing error inside the transaction block. Below have described one scenario of throwing error and catch it.
1.
try
2.
{
3. try
4.
{
5. ttsbegin;//ttslevel - 1
6.
ttsbegin;//ttslevel - 2
7. throw Exception::UpdateConflict; - it
will be catched in the outer scope of try catch (in line 19) even though you have catch inside try block
8.
ttscommit;
9. throw Exception::UpdateConflict; - it will be catched in inner scope (In line 12)
10. ttscommit;
11.
}
12. catch (Exception::UpdateConflict)
13. {
14. }
12. catch (Exception::UpdateConflict)
13. {
14. }
15. catch (Exception::DuplicateKeyException)
16. {
17.
}
18.
}
19. catch (Exception::UpdateConflict)
20.
{
21.
}
No comments:
Post a Comment