Show/Hide Toolbars

XSharp

Purpose

The BREAK statement raises a runtime exception.

Syntax

BREAK [expression ]

Arguments

expression An optional expression to throw.

Remarks

BREAK throws a runtime exception, causing execution to branch to the nearest RECOVER, CATCH or FINALLY block in a BEGIN SEQUENCE-RECOVER USING or TRY construct. If execution is not within a BEGIN SEQUENCE or TRY construct, the application will terminate.

The specified expression will be evaluated and received by the nearest RECOVER USING statement, if any, as a value of type USUAL. If the nearest RECOVER statement does not have a USING clause, the result of expression is discarded.

If expression is not specified, it defaults to NIL.

Example

FUNCTION foo
LOCAL e AS USUAL
BEGIN SEQUENCE
  bar( 1 )
RECOVER USING e
  ? "An exception has occurred, exception value is:", e
END SEQUENCE
 
FUNCTION bar( x )
IF Valtype(x) != STRING
  BREAK "Argument not a string!"
  ENDIF
 ...
RETURN