Question Locked
0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a piece of code written with an insert statement. If the insert statement works, I want to send an e-mail telling certain people the information inserted into the db (which works well). If it fails, I have a try/catch in the code which responds back with an error message on the entering persons screen (which works) and is to send an e-mail to our IT department (which works). Here is the catch...the error e-mail goes out irregaurdless if the insert statement works or not. If the insert goes through, the error message IS NOT displayed on the entering persons screen, yet I still get the error e-mail saying the insert failed, but I also get the e-mail that would be sent if the insert worked. If the insert fails, i get the error written to the screen and the error e-mail only. I have the error e-mail in the try/catch loop to catch the failure, and the "insert worked" email outside of and before the try/catch loop. Any suggestions?
2 replies
by brian Accepted solution
Clarifications
by tony hopkinson Accepted solution
But I'd have something like
Try{
DoInsert();
EmailSucess();
}
Catch(Exception (???) ex)
{
EmailFailure();
DisplayError()
}
Or better still IMHO
Success =false;
Try{
DoInsert();
Success =true;
}
Catch(Exception (???) ex)
{
DisplayError(ex)
}
Try
{ DoEmail(Success)
Catch(Exception (???)
{
DisplayError()
}
Don't like the idea of something as complex as email ina catchblock, if it throws and exception, you could be all over the place.
PS if you are using SQL server as your backend, you could do this in your sql you know
SQL Mail and Raiserror with a StoredProc.
This discussion is closed to new replies.
Trending Software posts
Sort by Trending
1 helpful
1 reply
0 helpful
20 replies
Question Unanswered
How Are Teams Testing AI-Generated Code Before Production?
0 helpful
0 replies
Discussion
Network Printer Works for Everyone Except Me
0 helpful
10 replies
0 helpful
4 replies