dlabar
New member
- Joined
- Aug 17, 2007
- Messages
- 4
- Programming Experience
- 1-3
I am trying to update data that is linked in two different databases. If the attempt to save the data in database 1 fails, I need to do some cleanup in database 2 and E-mail that the error occured. This results in something like this:
But if the CleanupDataInDatabase2 Sub fails, the email and throw statements will never get executed. So that results in something like this:
I want to call the sub CleanupDataInDatabase before e-mailing the error for the Save Data in Database Failed because the computer could possibly die when sending the e-mail before it cleans up the database.
Anyone have a better idea for how to handle this?
Is there a better way to create an inner exception than what is below?
I used "toString()" because it gives the error message as well as the actual line number and method of the outer exception, rather than "message()".
VB.NET:
data = GetDataToSave()
Try
SaveDataInDatabase1(data)
Catch exOuter as Exception
CleanupDataInDatabase2()
EmailAndWriteErrorToLog("Save data in database 1 failed!", exOuter)
Throw
End Try
But if the CleanupDataInDatabase2 Sub fails, the email and throw statements will never get executed. So that results in something like this:
VB.NET:
data = GetDataToSave()
Try
SaveDataInDatabase1(data)
Catch exOuter as Exception
Try
CleanupDataInDatabase2()
Catch exInner as Exception
Try
EmailAndWriteErrorToLog("Cleanup Data in Database 2 failed!", exInner)
Catch ex as Exception
'Unable to e-mail error, Nothing else to do.
End Try
Throw New Exception(exOuter.toString(), exInner)
Finally
Try
EmailAndWriteErrorToLog("Save data in database 1 failed!", exOuter)
Catch ex as Exception
'Unable to e-mail error, Nothing else to do.
End Try
End Try
Throw
End Try
I want to call the sub CleanupDataInDatabase before e-mailing the error for the Save Data in Database Failed because the computer could possibly die when sending the e-mail before it cleans up the database.
Anyone have a better idea for how to handle this?
Is there a better way to create an inner exception than what is below?
VB.NET:
Throw New Exception(exOuter.toString(), exInner)
I used "toString()" because it gives the error message as well as the actual line number and method of the outer exception, rather than "message()".