This is just a small modification to Jeff's answer:
I was looking for something like what Chris describes, and in particular, I wanted to handle the original exception after it was again thrown by a few generic exceptions, and I have only one handler that I could name for all points entrance. And since throwing the exception again will wrap it with its own type of exception, we need to add a loop to go through the internal exceptions and check the first exception thrown.
So here is the code I got into:
Public Sub HandelException(myEx As Exception) Try Dim InnerEx As Exception = myEx Do Until InnerEx.InnerException Is Nothing InnerEx = InnerEx.InnerException Loop If InnerEx.GetType = GetType(Exception1) Then 'Handle exception type 1 ElseIf InnerEx.GetType = GetType(Exception2) Then 'Handle exception type 2 ElseIf InnerEx.GetType = GetType(Exception3) Then 'Handle exception type 3 ElseIf InnerEx.GetType = GetType(Exception4) Then 'Handle exception type 4 ElseIf InnerEx.GetType = GetType(Exception) Then 'Handle generic system exception End If Catch ex As Exception 'Handel unlikely exception in exception handler LOL. End Try End Sub
The advantage of this is that you can have a wide selection of types of exceptions that you handle throughout the program, with lots of processing code, but you can handle them all in one place.
I know that this answer was a little late for this question, but I thought I would share it, if possible, to help someone look for the same thing that I was looking for.
source share