2
Answers

How to get the type of an exception

Photo of Ryan Brown

Ryan Brown

15y
5.3k
1
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;
     }

}

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

Answers (2)

0
Photo of Upendra Pratap Shahi
NA 13.3k 861.7k 9y
http://www.c-sharpcorner.com/UploadFile/40e97e/send-keys-to-application-programmatically-using-C-Sharp/


http://www.vbforums.com/showthread.php?621803-Sendkey-to-webbrowser

If helpful marked as Accepted Answer
0
Photo of Upendra Pratap Shahi
NA 13.3k 861.7k 9y
http://www.c-sharpcorner.com/UploadFile/40e97e/send-keys-to-application-programmatically-using-C-Sharp/


http://www.vbforums.com/showthread.php?621803-Sendkey-to-webbrowser

If helpful marked as Accepted Answer
0
Photo of Dipankar Biswas
NA 3k 125.6k 9y
hi..
 
it may help u..
 
Thanks..