Imports System.Windows.Forms

Public Class Class1

    Public Function MiddleFunction() As String

        ' Entering this block causes a handler to be written onto the stack

        Try
            BottomFunction()

            ' The code in this Finally handler is executed whenever execution leaves the
            ' Try block for any reason. We care most about the case in which BottomFunction
            ' throws an exception and the stack is unwound. Without the Finally handler,
            ' we'd have no chance to clean up from that exception.

        Finally
            MessageBox.Show("Finally handler in MiddleFunction")
        End Try

    End Function

    Public Function BottomFunction() As String

        ' Create a new Exception object, setting its "Message" property
        ' which can only be done in the constructor

        Dim MyException As New Exception("Exception thrown by BottomFunction")

        ' Set the new Exception's Source property, which can be done anywhere

        MyException.Source = "Understanding Microsoft.NET Chapter 2 ExceptionComponent"

        ' Throw the exception

        Throw MyException

    End Function


End Class
