Error Handling and Debugging
|
Error Handling and Debugging
leJOS NXJ provides several features for error handling and debugging, including:
The Remote Monitoring and Tracing facility, which is described in its own section below, can also be used for debugging. ExceptionsMost of the standard Java language exception classes are supported by leJOS, and user can create their own exception classes. Example: The following simplified version of the ExceptionTest example demonstrates what happens for an exception that is not caught – in this case an ArrayIndexOutOfBounds exception.
Data AbortsIf the leJOS firmware crashes you will normally a Data Abort. The screen shows the PC value where the failure occurred, and other details of the failure. The screen is something like: DATA ABORT PC 00140BAC AASR 1831BF01 ASR 00020601 OPCODE ??? DEBUG1 00020010 DEBUG2 00000000 The most common reason for data aborts is executing a file that is not a leJOS NXJ binary, or executing an incomplete leJOS NXJ file. If you get a data abort in any other case, you should report the error to the leJOS development team by posting the details on the leJOS NXJ forums. Back to topRemote DebuggingYou can use your PC as a remote console to display tracing statements generated your NXJ program. The lejos.nxt.comm.RConsole class has methods to it. Since there are no instances of this class, all methods are static. To start debugging, you use one of these methods:
The NXT displays and waits for the PC based monitor to connect. Then execute the nxjconsole program on your PC. When the connection is
established, the NXT displays If you use the variant of open with a timeout, it waits the specified number of seconds and if the debug monitor has not connected, proceeds without debugging. If the timeout is zero, it waits indefinitely. You can also use the ConsoleViewer application to display the output. Debug statements can be output using one of the methods:
If no successful open statement has been executed, the debug output is discarded. If there was a successful output, the string appears on standard out in the window or terminal that nxjconsole was run from, on the PC. When debugging is completed, you should call:
This closes the USB or Bluetooth connection. Example:
|