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 FunctionCode:'Error in an API right here ThrowError("Sending a message to my form.") MsgBox(GetLastError()) HandleError() If HasError Then Throw LastError()




Reply With Quote