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.

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

throwT_throwThrowThrowthrow (Operator)

Name

throwT_throwThrowThrowthrow — 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)

def throw(exception: Sequence[Union[int, str]]) -> None

Description

With the help of the operators trytryTryTryTrytry, catchcatchCatchCatchCatchcatch, endtryendtryEndtryEndtryEndtryendtry, and throwthrowThrowThrowThrowthrow 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 trytryTryTryTrytry, and dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheckdev_set_check as well as in the “HDevelop User's Guide”.

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

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

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

Attention

The export of the operators trytryTryTryTrytry, catchcatchCatchCatchCatchcatch, endtryendtryEndtryEndtryEndtryendtry, and throwthrowThrowThrowThrowthrow 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

ExceptionExceptionExceptionExceptionexceptionexception (input_control)  exception-array HTupleSequence[Union[int, str]]HTupleHtuple (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, throwthrowThrowThrowThrowthrow (as operator) returns 2 (H_MSG_TRUE). Otherwise, an exception is raised and an error code returned.

See also

trytryTryTryTrytry, catchcatchCatchCatchCatchcatch, endtryendtryEndtryEndtryEndtryendtry, dev_get_exception_datadev_get_exception_dataDevGetExceptionDataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data, dev_set_checkdev_set_checkDevSetCheckDevSetCheckDevSetCheckdev_set_check

Module

Foundation