|
GPS ToolKit.NET
About GPS ToolKit.NET Exceptions
GPS ToolKit.NET notifies your application of any errors it encounters by throwing one of the following exceptions:
- PortClosedException: GPS port is closed
- PortAlreadyOpenException: Port is already open
- PortOpenException: Could not open port. This may be because the port does not exist or is already in use.
- WriteErrorException: An error occurred while trying to write data to the GPS
- ArgumentException: An invalid argument was supplied
- GPSAutoDetectException: Unable to automatically detect GPS. You may still be able to open a port directly using the Open() method
- NoGPSDetectedException: Unable to detect GPS on the specified port with the baudrate/protocol combination specified (if any). You may be able to detect the GPS using AutoDetectGPS.
- NotSupportedException: This functionality is not supported by this GPS device or by the communications protocol currently in use.
- ProtocolNotSupportedException: GPS ToolKit does not currently support this protocol/data type.
- SystemPortsException: Unable to automatically detect system ports. You may still be able to open a port directly using the Open() method.
- TransferTimeoutException: Transfer timed out.
- DeviceInfoNotAvailableException: Device info is not available from the GPS
The following examples show how to handle these exceptions in your code.
Note that, for simplicity, the examples in the reference section do not include error handling constructs. You may examine the GPS ToolKit Test Panel sample project for examples of error handling in Visual Basic, C#, and C++.
Visual Basic.NET
GPS ToolKit.NET errors are handled in Visual Basic.NET using either structured exception handling similar to C# and C++, or by using the familiar unstructured On Error Goto construct. When using structured handling, you must specifically reference the Exception variable as type System.Exception. This is because GPS ToolKit.NET includes "Windows.h", which globally defines its own exception type, and Visual Basic's indifference to case will cause it to default to the exception type. The following example traps an error and displays the error message using structured exception handling:
Try
myGPSToolKit.Open("COM1")
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
When using unstructured (VB6 style) exception handling, detailed error information can be found in the application's global Err object. For example, the following code traps an error and displays a description in a message box:
Private Sub MySub()
On Error GoTo MyErrorHandler
myGPSToolKit.Open "COM1"
Exit Sub
MyErrorHandler:
MsgBox(Err.Description)
End Sub
C#
GPS ToolKit.NET errors are handled in C# using standard try/catch blocks. The following code traps an error and displays a description in a message box:
try
{
myGPSToolKit.Open("COM1");
}
catch(Exception Ex)
{
MessageBox.Show(Ex.Message);
}
C++
GPS ToolKit.NET errors are handled in C++ using standard try/catch blocks. The following code traps an error and displays a description in a message box:
try
{
myGPSToolKit->Open("COM1");
}
catch(Exception *Ex)
{
MessageBox::Show(Ex->Message);
}
|