assert [Condition] assert [Condition] error [Context [| Format]] assert [Condition] fault [Context [| Format]] assert [Condition] catch Handler
The Assert command is used to detecting and raise exceptions. When the condition is not met, an exception is raised. Otherwise the program continues execution at the next command. Exceptions may be managed by the programmer or default handlers can be used. Assertions can be ignored to increase performance. This is controlled through the exception testing facility.
A context string may also be included that is passed onto an exception handler when an exception occurs. The context argument uses the same syntax and semantics as Print command arguments.
When the Error, Fault, and Catch keywords are coded immediately after the assert then the assertion is unconditional. If you have variables with these names that you'd like to use in a condition then enclose them in parenthesis.
assert (Error) = 0 Error Context; Error is used as a variable and keyword.
Exceptions may also be triggered when an operation is executed for which the result is undefined. Division by zero or an array index out of bounds are common examples. Handlers may also be provided to handle these situations.
The default exception handler fields exceptions when no other has been provided. A comment on the same line as the Assertion will be reported by the default handler along with the context string. If no comment is present or the exception is the result of an undefined operation, the handler reports a generic message. The default handler is included for debugging and for reporting messages with no context.
Context sensitive exception handling is accomplished by providing handlers. Handlers can be directly coupled or coupled through the exception testing facility.
The exception testing facility couples test cases, exceptions, and handlers. Assertions that are not matched with a test case will be ignored. Checks can be used freely in a program for debugging and will automatically be removed in the final system.
The coupling method used by the exception handler allows several handlers to be triggered from a single check point in a program. A handler may be associated with each path to that point in the calling hierarchy.
Each exception test case sets up conditions to trigger an exception, enters the system under test, and performs any clean up operations. The path from the entry point to the check point will be associated with the handler specified by the test case. After the exception is recorded, control is passed back to the test case which resets any variables needed to prepare for another test case.
When the exeption is triggered in a running system, the corresponding handler will be invoked. When the handler completes, it will return from the same point at which the test case originally called. Any recursion and string stuff will be cleaned up along the calling path.
Exceptions can also be caught by associating a handler with a method. Any exception called below the method not caught by a specific handler will cause control to be passed to the handler. The handler must have the same parameters as the method. In a class declare a handler as:
catch Method.Handler
The Handler will not be used unless it is explicitly built using the class dependency mechanism. This allows a handler to be declared in a class, but the user of the class can determine whether or not they want to use the handler.