Use the tabs on the upper right to switch to a different programming language.

Use the tabs on the upper right to switch to a different programming language.

Use the tabs on the upper right to switch to a different programming language.

throwT_throwThrowThrow (Operator)

Name

throwT_throwThrowThrow — Throws a user-defined exception or rethrows a caught exception.

Signature

throw( : : Exception : )

Herror T_throw(const Htuple Exception)

void Throw(const HTuple& Exception)

static void HOperatorSet.Throw(HTuple exception)

Description

With the help of the operators trytryTryTryTry, catchcatchCatchCatchCatch, endtryendtryEndtryEndtryEndtry, and throwthrowThrowThrowThrow 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 trytryTryTryTry, and dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheck as well as in the “HDevelop User's Guide”.

The operator throwthrowThrowThrowThrow provides an opportunity to throw an exception from an arbitrary place in the program. This exception can be caught by the catchcatchCatchCatchCatch operator of a surrounding trytryTryTryTry-catchcatchCatchCatchCatch 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 ExceptionExceptionExceptionExceptionexception 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 throwthrowThrowThrowThrow it is possible to rethrow an exception that was caught with the operator catchcatchCatchCatchCatch. This may be sensible, for instance, if within an inner trytryTryTryTry-catchcatchCatchCatchCatch-endtryendtryEndtryEndtryEndtry 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 trytryTryTryTry-catchcatchCatchCatchCatch-endtryendtryEndtryEndtryEndtry block.

For rethrowing a caught exception, it is possible to pass the ExceptionExceptionExceptionExceptionexception tuple that was caught by the catchcatchCatchCatchCatch operator directly to the ExceptionExceptionExceptionExceptionexception parameter of the throwthrowThrowThrowThrow operator. Furthermore, it is possible to append arbitrary (but no iconic) user data to the ExceptionExceptionExceptionExceptionexception tuple, that can be accessed after catching the exception as 'user_data'"user_data""user_data""user_data""user_data" with the operator dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionData:

try ... catch (Exception) ... UserData := ... throw ([Exception, UserData]) endtry

Attention

The export of the operators trytryTryTryTry, catchcatchCatchCatchCatch, endtryendtryEndtryEndtryEndtry, and throwthrowThrowThrowThrow 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.

Parameters

ExceptionExceptionExceptionExceptionexception (input_control)  exception-array HTupleHTupleHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*)

Tuple returning the exception data or user defined error codes.

Result

If the values of the specified parameters are correct, throwthrowThrowThrowThrow (as operator) returns 2 (H_MSG_TRUE). Otherwise an exception is raised and an error code returned.

See also

trytryTryTryTry, catchcatchCatchCatchCatch, endtryendtryEndtryEndtryEndtry, dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionData, dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheck

Module

Foundation