I have a BO method that must do two operations to fulfill its contract.
- insert a record into the db
- send an email notification containing the metadata for the record
Both are handled with calls to individual DAO methods responsible for completing the action.
I do not trap exceptions in my DAO, I handle and publish them in the BO. The first call is to the DAO to insert, and can throw a NullReferenceException or one of the sql exceptions. The email method uses SmtpClient.Send which can throw a slew of exceptions.
Is it possible to force the child method that calls the email functionality to return only one type of exception, a custom one, through an attribute?
To illustrate this:
public void AddSupportTicket(SupportTicketDTO ticket)
{
try
{
supportTicketDAO.Insert(ticket);
email.SendNotification(ticket);
}
catch (ExceptionA exc) { ... } // both of the methods can throw exceptions that
catch (ExceptionB exc) { ... } // can overlap. I just care about returning
catch (ExceptionC exc) { ... } // a custom EmailException or DataException
}
I can wrap each child method call in its own try catch and throw the custom exception I want, but thats just another level of try catch that gets trapped by another try catch in AddSupportTicket, and then one in the UI to redirect to an intelligent error, so that doesn't sound great to me.
How should I efficiently throw the correct custom exception?