throw
— Throws a user-defined exception or rethrows a caught exception.
throw( : : Exception : )
With the help of the operators try
, catch
, endtry
,
and throw
it is possible to implement a dynamic exception handling
in HDevelop, which is comparable to the exception handling in C++
and C#. The basic concepts of the exception handling in HDevelop are
also described at the operators try
, and
dev_set_check
as well as in the “HDevelop User's Guide”
.
The operator throw
provides an opportunity to throw an exception
from an arbitrary place in the program.
This exception can be caught by the catch
operator of a
surrounding try
-catch
block.
By this means the developer is able to define his own specific error or
exception states, for which the normal program execution is aborted in
order to continue with a specific cross-procedure exception handling,
e.g., for freeing resources or restarting from a defined state.
In such a user-defined exception a nearly arbitrary tuple can be thrown
as the Exception
parameter, merely the first element of the tuple
should be set to a user-defined error code >= 30000.
In addition, with the help of the operator throw
it is possible to
rethrow an exception that was caught with the operator catch
.
This may be sensible, for instance, if within an inner
try
-catch
-endtry
block (e.g., within an external
procedure) only specific exceptions can be handled in an adequate way and
all other exceptions must be passed to the caller, where they can be caught
and handled by an outer try
-catch
-endtry
block.
Exception
tuple that was caught by the catch
operator
directly to the Exception
parameter of the throw
operator.
Furthermore, it is possible to append arbitrary (but no iconic) user
data to the Exception
tuple, that can be accessed after catching
the exception as 'user_data' with the operator
dev_get_exception_data
:
try
|
...
|
catch(Exception)
|
...
|
UserData := ...
|
throw([Exception, UserData])
|
endtry
|
The export of the operators try
, catch
, endtry
,
and throw
is not supported for the language C, but only for the
languages C++, C# and VisualBasic/.NET.
Only the latter support throwing exceptions across procedures.
Exception
(input_control) exception-array →
(integer / string)
Tuple returning the exception data or user defined error codes.
If the values of the specified parameters are correct,
throw
(as operator) returns 2 (
H_MSG_TRUE)
. Otherwise, an
exception is raised and an error code returned.
try
,
catch
,
endtry
,
dev_get_exception_data
,
dev_set_check
Foundation