exception
This function asserts an exception in a similar way as programming errors are handled This feature is very useful if you want to assert an error message associated plausible info (including listing a few lines of code above the place where the exception is happening). The exception shows up like any other exception you typically encounter, for example divisions by zero or unable to find table columns.
Indirect parameter passing is enabled.
2-3
No. | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
1 input |
string | Action Supported values: pause, interactive, throw, stop, end, exit, abort | ||||||||
2 input |
string | Message Provide the error message. If you need to compose multiple values like in an echo() call, then use the compose() funtion to put all values into them. | ||||||||
Opt. 3 input |
numeral | Calling hierarchy The calling hierarchy determines the hierarchical calling level of the code where to eventually display the lines of code along with the exception message. The level increases by 1 with every call to user functions, and starting B4P programs with start or include.
Default value: 0 |
define function ( square root, { { n, numeral } } )
{
// If the last parameter is 0, then the code up here will be shown and not at the function call.
if (n[] < 0) exception( stop, "1st parameter: Negative values are not allowed for square roots", 1 );
return( sqrt(n[]) );
}
// Main Program
{
echo("Try a negative square root.");
a[] = square root( -1 );
}
Try a negative square root.
Row #: Code Text _______________________________________________________
7: }
8:
9: // Main Program
10:
11: {
12: echo("Try a negative square root.");
13: a[] = square root( -1 );
^
1st parameter: Negative values are not allowed for square roots
Code execution will stop. Going to interactive mode
________________________________________________________________________
Type 'help' for help, 'docs' for B4P docs, 'web docs' for online docs.
>>