ClassesClassesClassesClasses | | | | Operators

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

throwT_throwThrowthrowThrowThrow (Operator)

Name

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

Signature

throw( : : Exception : )

Herror T_throw(const Htuple Exception)

Herror throw(const HTuple& Exception)

void Throw(const HTuple& Exception)

void HOperatorSetX.Throw([in] VARIANT Exception)

static void HOperatorSet.Throw(HTuple exception)

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_checkDevSetCheckdev_set_checkDevSetCheckDevSetCheck 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 ressources 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_dataDevGetExceptionDatadev_get_exception_dataDevGetExceptionDataDevGetExceptionData:

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

Attention

The export of the operators trytryTrytryTryTry, catchcatchCatchcatchCatchCatch, endtryendtryEndtryendtryEndtryEndtry, and throwthrowThrowthrowThrowThrow is not supported for the languages C and VisualBasic 6.0, but only for the languages C++, C# and VisualBasic/.NET. Only the latter support throwing exceptions across procedures.

Parameters

ExceptionExceptionExceptionExceptionExceptionexception (input_control)  exception-array HTupleHTupleHTupleVARIANTHtuple (integer / string) (int / long / string) (Hlong / HString) (Hlong / char*) (Hlong / BSTR) (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_dataDevGetExceptionDatadev_get_exception_dataDevGetExceptionDataDevGetExceptionData, dev_set_checkdev_set_checkDevSetCheckdev_set_checkDevSetCheckDevSetCheck

Module

Foundation


ClassesClassesClassesClasses | | | | Operators