Error Handling
This section discusses some error handling techniques and tips for use in JWAVE wrapper functions.
Using the MESSAGE Procedure
Use the PV‑WAVE MESSAGE procedure to generate error messages from JWAVE wrapper functions. The error text that MESSAGE produces is automatically sent to the client as a Java Exception (specifically, a JWaveWrapperException object). The MESSAGE procedure also causes the wrapper function to stop processing (by default).
For detailed information on MESSAGE, refer to the PV‑WAVE Reference.
Trapping Errors
If you use PV‑WAVE error handling routines (such as ON_ERROR_GOTO or ON_ERROR) to trap and handle errors in a JWAVE wrapper function, be sure to set !Error=0 immediately after the error trap to ensure that the error is not reported back to the client.
ON_ERROR and ON_ERROR_GOTO are described in the PV‑WAVE Reference.
Using the Expect Keywords
GETPARAM takes a set of optional keywords that can be used for trapping input errors. These keywords are only used in conjunction with the Value keyword. (This is because they are used to test values that are passed from the client.)
These keywords all begin with the word Expect. They are:
ExpectType = type_code /ExpectNumeric /ExpectString ExpectArray = [
dim1,
dim2, ... ] or
/ExpectArray /ExpectScalar The first three keywords (ExpectType, ExpectNumeric, and ExpectString) produce an error if the returned parameter does not match the expected data type. The valid data type codes that you can use with JWAVE are listed below.
1—BYTE
2—INT
13—INT32
3—LONG
4—FLOAT
5—DOUBLE
7—STRING
The keyword
ExpectArray produces an error if the input parameter is not an array of the specified dimensions. For more information on the
Expect* keywords, see
"GETPARAM Function" on page 171.
The keyword ExpectScalar produces an error if the input parameter is not a scalar or a 1-element array. If the parameter is a 1-element array, then the function returns that element as a scalar.
As the following lines show, you can use reasonable combinations of the Expect* keywords in a single GETPARAM function.
; y must be a numerical array
y = GETPARAM(client_data, 'Y', /Value, /ExpectArray, $
/ExpectNumeric )
; xcnt and ycnt must be numerical scalars
xcnt = GETPARAM(client_data, 'XCENTER', /Value, Default = 0.5, $
/ExpectScalar, /ExpectNumeric )
ycnt = GETPARAM(client_data, 'YCENTER', /Value, Default = 0.5, $
/ExpectScalar, /ExpectNumeric )
; title must be a scalar string.
title = GETPARAM(client_data, 'TITLE', /Value, $
Default = 'The Title', /ExpectScalar, /ExpectString)