Results 1 to 7 of 7

Thread: [RESOLVED] Exception Problems.

Threaded View

  1. #5
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: [RESOLVED] Exception Problems.

    Since it fits here any ways, same as kevin, a few functions to shorten it all. Import interopservices btw.

    Code:
        Public Shared Function HasError() As Boolean
            Return Marshal.GetLastWin32Error() <> 0
        End Function
        Public Shared Function LastError() As Exception
            Return New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())
        End Function
        <DebuggerStepThrough()> _
        Public Shared Sub HandleError()
            If HasError() Then Throw LastError
        End Sub
    
        Public Sub ThrowError(Optional ByVal location As String = "")
            Dim ex As New System.ComponentModel.Win32Exception(Runtime.InteropServices.Marshal.GetLastWin32Error())
            If ex.NativeErrorCode <> 0 Then MessageBox.Show(ex.Message, "Error at " & location, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Sub
    
        Public Function GetLastError() As String
            Return New System.ComponentModel.Win32Exception(Runtime.InteropServices.Marshal.GetLastWin32Error()).Message
        End Function
    Code:
    'Error in an API right here
    ThrowError("Sending a message to my form.")
    MsgBox(GetLastError())
    HandleError()
    If HasError Then Throw LastError()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width