I am doing this in the Form_Load() event of a desktop application
string strDay = DateTime.Now.DayOfWeek.ToString().ToUpper();
try
{
fnBirthDayReminder();
}
catch (Exception ex)
{
}
try
{
if (strDay == "SUNDAY" || strDay == "TUESDAY" || strDay == "THURSDAY")
{
fnAwaitingLeaveApplicationReminder();
}
}
catch (Exception ex)
{
}
try
{
fnLeavePlanRemainder();
}
catch (Exception ex)
{
}
try
{
fnContractExpiryRemainder();
}
catch (Exception ex)
{
}
Application.Exit();
But the application exists just after the execution of the first try..catch block. Even if I place BreakPoint on following try..catch’s, these breakpoints were not hit. I am really confused about such mysterious behavior. Please help !
For you all,
“if one method throws an exception, the other methods will not run.” this is the main reason I am using separate try..catch blocks. So that, even if a function gives an exception, the next can execute.
Edit2
Can you suggest me a nice approach other than I am using here to execute the next function even if an exception occurred during the first function. The way some of you are suggesting (calling all the functions in a single try block with multiple catch blocks) will not do, that’s for sure. I am thinking about recoding the methods without spending more time.
Have you tried putting a breakpoint in the first catch block, and examining the exception message / stack trace? I’ve observed sometimes that the application can exit for certain types of exception, e.g. stackoverflow, rather than the expected behaviour.
Finally, your methods shouldn’t throw under normal circumstances. Try to find out why they are and remove the bugs.