xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Break()

Exits from a BEGIN SEQUENCE block.

Syntax

Break( <Expression> ) --> NIL

Arguments

<Expression>
This is an arbitrary expression whose value is passed to the RECOVER USING statement of the last BEGIN SEQUENCE .. ENDSEQUENCE block. Use the value NIL for <Expression> to pass no expression value.

Return

The return value is always NIL.

Description

The Break() function branches program flow to the RECOVER statement of the last BEGIN SEQUENCE block and passes the value of <Expression> to the variable defined with the USING <errorVar> option, if defined. If BEGIN SEQUENCE is used with no RECOVER statement, program flow continues with the next executable statement following ENDSEQUENCE.

Break() is mainly used in conjunction with error handling, when a user defined code block replaces the standard ErrorBlock().

Info

See also:BEGIN SEQUENCE, ErrorBlock(), ErrorNew(), Throw(), TRY...CATCH
Category: Error functions
Source:vm\break.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows a typical usage scenario for the Break() function.
// It is called from within a user defined error code block. The
// error code block receives an error object created by the xHarbour
// runtime system. The error object is passed to Break() and ends up
// in the RECOVER USING variable. The error condition can then be
// inspected.

   PROCEDURE Main
      OpenDatabase()

      ? "Files are open"
      ? "Program can start"
   RETURN


   PROCEDURE OpenDatabase
      LOCAL oError
      LOCAL bError := ErrorBlock( {|e| Break(e) } )

      BEGIN SEQUENCE
         USE Customer NEW SHARED
         USE Invoice  NEW SHARED

         ErrorBlock( bError )
      RECOVER USING oError
         ErrorBlock( bError )

         ? "Unrecoverable error:"

         ? oError:description
         ? oError:operation
         ? oError:subsystem
         QUIT
      ENDSEQUENCE
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe