throw <exception>
Throw an exception.
<exception>
An exception, or the result of an exception function.
none
This command is designed for user errors which can be caught by a catch command block in the current (or parent)) command frame, and processed accordingly. It is typically executed within a try command block.
If the current command frame is the top-level keyboard command frame or an interrupt command frame, or if there is no active enclosing try command block in the current (or parent) command frame, the exception will be printed, because there is no relevant catch command block.
Unlike exceptions thrown automatically by system errors, this command will always through an exception, irrespective of the value of throw_level.
Prompt the user for a file whose contents are to be displayed. If no name is supplied, or the file does not exist throw an error and catch
try { string fname ask 'Please give file name',fname unless (fname) { throw error_exception('Null file name supplied',555) } unless (fexist(fname)) { throw error_exception('File does not exist',556) } # Do other stuff ... walpha fname } catch exc { # Print the error tell <'User error (',exc.code,'): ',exc.text> }
The offending command is executed within a try block, the system error is caught by a catch block and processed appropriately. Part of the exception gets printed, thus:
We have caught the exception, code: 2011
Commands: |
|
Functions: |
|
Identifiers: |
throw_level (numeric) |
Structures: |