Catch System.ComponentModel.Win32Exception

  • Thread starter Thread starter Lucas Tam
  • Start date Start date
L

Lucas Tam

Is it possible to catch a System.ComponentModel.Win32Exception? VB.NET
seems to bypass System.ComponentModel.Win32Exception... I need to catch one
level up at System.InvalidOperation. Is this normal?
 
Lucas Tam said:
Is it possible to catch a System.ComponentModel.Win32Exception?
Yes.

VB.NET seems to bypass System.ComponentModel.Win32Exception...
I need to catch one level up at System.InvalidOperation.

Looking at the class hierarchies in MSDN, these two Exception classes
are only distantly related :

System.Object
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.ComponentModel.Win32Exception

System.Object
System.Exception
System.SystemException
System.InvalidOperationException

So in order to catch either, you'd have to catch the
System.SystemException level and test the type of the Exception
class you're handed, as in :

Catch ex as System.SystemException
If Typeof ex Is System.InvalidOperationException Then
. . .

HTH,
Phill W.
 
Looking at the class hierarchies in MSDN, these two Exception classes
are only distantly related :

Thanks, I was checking my debugger and the InnerException type was a
System.ComponentModel.Win32Exception. The outer exeption was a
System.InvalidOperation.

What I don't understand is why I can't catch the InnerException. I always
assumed the InnerException is a more specific exception (a lower level
exception). Maybe I don't fully understand VB.NET's exception model.
 
Back
Top