Netor Technologies

Try-Catch-Beta  

Try catch blocks are an important part of any application (provided the language supports them) but they can make debugging in a beta environment difficult. I use the following design method to set up proper error handling while still being able to take advantage of the Visual Studio debugger.

// C# Example
public void MyFailProneFunction()
{
   if(!BETA)
   {
      try
      {
         MyFailProneFunction_Base();
      }
      catch(Exception ex)
      {
         // ... Exception handling code ...
      }
   }
   else
         MyFailProneFunction_Base();
}

public void MyFailProneFunction_Base()
{
   // ... Functionality Code ...
}

Or if you prefer VB.Net...

'VB.Net Example
Public Sub MyFailProneSub()
   If Not BETA Then
      Try
         MyFailProneFunction_Base()
      Catch ex as Exception
         ' ... Exception handling code ...
      End Try
   Else
      MyFailProneFunction_Base()
   End If
End Sub

Public Sub MyFailProneSub_Base()
   ' ... Functionality Code ...
End Sub

This assumes there is a global boolean value BETA defined elsewhere in the code to specify whether the application is in a production or beta environment.

By leaving the function call outside of the try catch block when in beta mode the debugger will function normally. Visual Studio has a setting to break on all exceptions but this design allows you to create several different beta booleans to specify precisely which portion of code you want exceptions to break on.

Archives

copyright© 2008 netor technologies