Discussion:
Example of T-SQL exception handling within a transaction?
Richard Kaye
2018-09-13 21:05:00 UTC
Permalink
Log your exceptions to a text file? 😊
--
rk

-----Original Message-----
From: ProfoxTech <profoxtech-***@leafe.com> On Behalf Of Malcolm Greene
Sent: Thursday, September 13, 2018 5:02 PM
To: ***@leafe.com
Subject: Example of T-SQL exception handling within a transaction?

Anyone have an example of how to trap and exception within a T-SQL transaction and save diagnostic details on why the transaction failed to an error log? If you insert the exception data to an error table this information gets lost when you rollback the transaction. I'm sure I'm missing something obvious :) Thanks, Malcolm


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@BN6PR10MB1299.namprd10.prod.outlook.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who ar
Stephen Russell
2018-09-13 21:22:11 UTC
Permalink
https://logicalread.com/sql-server-exception-handling-try-catch-throw-mc03/

Good description there on how to write one and that the THROW is necessary
within a transaction. I learned something in this because I rarely ever
write transactions due to locks being applied while it is running.
Post by Richard Kaye
Anyone have an example of how to trap and exception within a T-SQL
transaction and save diagnostic details on why the transaction failed to
an error log? If you insert the exception data to an error table this
information gets lost when you rollback the transaction. I'm sure I'm
missing something obvious :)
Thanks,
Malcolm
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Christof Wollenhaupt
2018-09-14 06:56:52 UTC
Permalink
Post by Richard Kaye
Anyone have an example of how to trap and exception within a T-SQL
transaction and save diagnostic details on why the transaction failed to
an error log? If you insert the exception data to an error table this
information gets lost when you rollback the transaction. I'm sure I'm
missing something obvious :)
Yes, you log into a variable, roll back the transaction in the CATCH block and then insert the variable into the error log table.
--
Christof


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/F9812B11-B091-48A2-A805-***@wollenhaupt.org
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Loading...