| Gentee Programming Language > Documentation > Syntax | Download documentation |
The exception function (command) defines the exception handlers. If a function throws an exception, the last exception handler function will be called. If the exception has not been handled, the previous handler function will be called. One handler-function can be defined in the function. An exception handler will be undefined when the function, where the handler was defined, has completed. An identifier of the exception handler-function is specified as the argument of the exception function.
<exception> ::= exception '('<expression>')'
An exception handler-function must have two arguments. The first argument must be of the uint type and defines an exception code. The second argument can be of any type ( except long, double, ulong ). The function returns the following values:
0 - the exception has not been handled. The previous handler-function will be called.
1 - the exception has been handled. If the handler-function returns this value, functions called after the handler had been defined, will be terminated sequentially. Furthermore, the function, where the given handler was defined, will be also terminated. All the functions will return zero.
2 - proceed with the program execution.
func uint myexcept( uint code, str param )
{
if code == $MYEXCEPT
{
print( param )
return 1
}
return 0
}
func a
{
...
if i < 10 : throw( $MYEXCEPT, "The i value cannot be less than 10" )
...
}
func uint b
{
exception( &myexcept )
...
a()
print("This message cannot be shown if there is an exception in a()\n")
return 1
}
func main
{
print( "The result of b() function = \( b())\n" )
print("This message is always shown.\n")
}
In case of defining the second handler, the first handler will be undefined.
// Here we can proceed with all exceptions
func uint myexcept1( uint code, collection param )
{
...
}
func uint myexcept2( uint code, collection param )
{
...
}
func main
{
exception( &myexcept1 )
... // All exceptions will be directed to myexcept1
exception( &myexcept2 )
// myexcept1 is disable
// All exceptions will be directed to myexcept2
...
}
See also
Exception throwing - throw Termination handling - finally
Copyright © 2004-2006 Gentee Inc. All rights reserved. |