Exeption Handling Block multiple forms in VB.Net

Topics: Exception Handling Application Block, General discussion
Aug 14, 2011 at 2:40 PM

Hello,

I have a question about the Exeption Handling Block. I have a multiple WindowsForms application and like to use this block. But how can I use it in multiple forms. Must I write code in every form or can I use a class and use this class in my forms.

I'm working with an Oracle database 

can someone point me to some examples I have read the Microsoft Enterprise Library 5.0 - Hands On Labs and have create some policy's but how can I call his in my forms.

Thanks

Aug 15, 2011 at 9:08 AM

Hi,

What particular exception handling will you have to use? Currently, there are two ways to handle exception: Process and HandleException (you can refer here for more details). Either of the two, needs to be called on where you're expecting the exception will be thrown. You may create a static wrapper class for these methods and call that wrapper class instead.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 15, 2011 at 9:27 PM

I have tryed it like this:

Catch ex As Exception
Dim rethrow As  Boolean
rethrow = ExceptionPolicy.HandleException(ex, "UI Beleid") 

 

if (rethrow) Then  Throw
MessageBox.Show("Er heeft zich een onverwachte uitzondering voorgedaan " & _ 
                
"er is een logbestand aangemaakt. " & _     
                 
"Neem s.v.p. contact op met supportafdeling.")

I get an windows errormessage but not the Messagebox I want

 

Aug 15, 2011 at 10:47 PM

Thanks Noel,

I have created a new try like this:

Private Shared Sub HandleException(ByVal ex As Exception, ByVal policy As String)
        Dim rethrow As Boolean = False
        'Resolve an Exeption Manager instance
        Dim exManager As ExceptionManager _
            = EnterpriseLibraryContainer.Current.GetInstance(Of ExceptionManager)()
        Try
            rethrow = exManager.HandleException(ex, policy)
        Catch innerEx As Exception
            Dim errorMsg As String
            errorMsg = String.Format("U heeft 1 of meer velden leeg gelaten", policy, Environment.NewLine, innerEx.ToString())
            MessageBox.Show(errorMsg, "Oeps!!!!", _
                            MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End Try
    End Sub

And make the catch like this and it works for me

        Catch ex As Exception
            HandleException(ex, "UI Beleid")
 
Where "Beleid" is my policy and creates a logfile in a log map.