Hello all,
I am tasked with creating a base exception handler that will handle a
bunch of clean-up that needs to happen based on the type of exception
thrown. So, for example, I will have (at least in my initial thoughts)
a base class like:
public abstract class BaseExceptionHandler
{
public void HandleException(Exception ex)
{
Do something based on exception type;
}
public abstract class NewExceptionHandler : BaseExceptionHandler
{
Any new or overridden logic
NewExceptionHandler exHandler = new NewExceptionHandler();
try
{
Whatever
{
exHandler.HandleException(ex);
{
exHandler.HandleException(ex);
How, given that all of these inherit from Sytem.Exception do I find
out the actual type of the exception thrown? I know I am missing
something obvious…
Thanks in advance!
rbr
I am tasked with creating a base exception handler that will handle a
bunch of clean-up that needs to happen based on the type of exception
thrown. So, for example, I will have (at least in my initial thoughts)
a base class like:
public abstract class BaseExceptionHandler
{
public void HandleException(Exception ex)
{
Do something based on exception type;
}
}
Then each inherited exception type will declare like: public abstract class NewExceptionHandler : BaseExceptionHandler
{
Any new or overridden logic
}
Then the implementation needs to look like: NewExceptionHandler exHandler = new NewExceptionHandler();
try
{
Whatever
}
catch (MissingDependencyException ex) {
exHandler.HandleException(ex);
}
catch (DividebyzeroException ex) {
exHandler.HandleException(ex);
}
… How, given that all of these inherit from Sytem.Exception do I find
out the actual type of the exception thrown? I know I am missing
something obvious…
Thanks in advance!
rbr

patrickRank #4,458 · 342 reputationPosted May 29, 2009, 7:18 AM EDT
catch (MissingDependencyException ex)
{
exHandler.HandleException(ex, ex.getType());
}
Hope this helps at least a little.
Ryan Brown9 reputationPosted May 29, 2009, 8:24 AM EDT
Thank you very much for your response.
rbr