Examples
Previous  Next

Here are some example structures for exception handling Subs.

An exception assigned to Exception.ControlRef may be identified by either its' Name or FullName properties. The contents of the Message property will vary with the locale of the OS version so it is probably not wise to rely on the contents of the message to indicate the source of the exception. Unfortunately there seems to be no definitive list of exceptions that the .NET Framework can throw so experiment is probably needed to simulate the most likely problems, such a missing file name on open, to identify the commonest exception names. Those can then be identified and dealt with in the code while unknown ones can be displayed to the user for them to decide the action to be taken. As mentioned above the Message property will return a user friendly string description that depends upon the localization of the Operating System.


' simple exception handling
Sub example1
  ErrorLabel(ex11)
            ' ... program code
            Return
ex11:
            'Exception1.ControlRef = B4PObject(6)
            '.... handle exception
End Sub
 
 ' more complicated exception handling
Sub example2
  ErrorLabel(ex21)
            ' ... program code might cause on sort of exception
  ErrorLabel(ex22)
            ' ... program code might cause another sort of exception       
            Return
ex21:
            'Exception1.ControlRef = B4PObject(6)
            '.... handle one sort of exception
            Return
ex22:
            'Exception1.ControlRef = B4PObject(6)
            '.... handle another sort of exception
            Return
End Sub


' handle exception in exception handling
Sub example3
  ErrorLabel(ex31)
            ' ... program code
            Return
ex31:
            ErrorLabel(ex32)
            'Exception1.ControlRef = B4PObject(6)
            '.... handling first exception may cause another
            Return
ex32:
            ErrorLabel(ex32) ' ensure any further exceptions come here 
            ' ... handle exception in exception
End Sub