Operator Reference

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)

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 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_checkDevSetCheckDevSetCheckdev_set_check 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. If different user-defined exception states are possible, they can be distinguished using different error codes (>= 30000) in the first element or by using additional elements.

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_dataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data:
trytryTryTrytry
...
catch(Exception)catch(Exception)Catch(Exception)Catch(Exception)catch(Exception)
...
UserData := ...
throw([Exception, UserData])throw([Exception, UserData])Throw([Exception, UserData])Throw([Exception, UserData])throw([Exception, UserData])
endtryendtryEndtryEndtryendtry

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 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, 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_dataDevGetExceptionDataDevGetExceptionDatadev_get_exception_data, dev_set_checkdev_set_checkDevSetCheckDevSetCheckdev_set_check

Module

Foundation