I am working in a windows service (using VB.Net) for internal use of my department. When ever a certain type of exception (FooException
for now on) is captured, I follow the same logic:
- Log the exception
- Send an email to someone.
In order to reuse code and not to copy-paste the same lines in every catch FooException
block I have created a FooExceptionHandler
method inside my ExceptionHandling
class. So I ended up with a code like this:
FooExceptionHandler(fooException)
{
//log the exception
try
{
//send email
}
catch SmtpException
{
//log the smtp exception
}
}
My question is about how to organize the code. Should this be a static method? Should all the exception handling class be static? Should it be a singleton? Should it be object-oriented?
If the object-oriented case is the best way, should I create a new object in every catch block or is it better to have a class variable?