xHarbour Reference Documentation > Function Reference |
Sets the exit code of the xHarbour application.
ErrorLevel( [<nNewExitCode>] ) --> nCurrentExitCode
The function returns a numeric value which is the current exit code of the xHarbour application.
The ErrorLevel() function defines or retrieves the exit code of the xHarbour application. The exit code can be viewed as the return value of the application that is passed to the calling process upon termination. Normally, the calling process is the operating system. When the xHarbour application ends regularly, the exit code is set to 0. If the application quits due to a runtime error, the default exit code is set to 1. The exit code can be queried in a batch file using the ERRORLEVEL command of the operating system. This way, regular and irregular program termination can be detected.
ErrorLevel() allows for user-defined exit codes since numeric values in the range of 0 to 255 can be passed to the function. A user-defined exit code is retained until a new value is passed to ErrorLevel().
See also: | ErrorBlock(), ErrorSys(), Getenv(), QUIT |
Category: | Error functions , Debug functions |
Source: | vm\hvm.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// This example consists of three files: MYSTART.BAT, a batch processing // file executed by the operating system, and two PRG files containing // the code for two xHarbour applications. // The ErrorLevel() exit code of both applications is queried in the // batch file to run both xHarbour applications as alternating processes // when the user presses the Y key. @ECHO OFF REM This is the command file MYSTART.BAT :Start ECHO Main application module MyProgram.exe IF ERRORLEVEL 25 GOTO Reorg GOTO Exit :Reorg ECHO Data reorganization module Reorganize.exe IF ERRORLEVEL 26 GOTO Start :Exit ECHO Application has ended REM *EOF* /* * Program: MyProgram.exe */ PROCEDURE Main ? "press <Y> to re-organize data" ? Inkey(0) IF Chr( LastKey() ) $ "yY" ErrorLevel( 25 ) ENDIF RETURN /* * Program: Reorganize.exe */ PROCEDURE Main ? "Data re-organization is running." ? ? "press <Y> to re-start main program" ? Inkey(0) IF Chr( LastKey() ) $ "yY" ErrorLevel( 26 ) ENDIF RETURN
http://www.xHarbour.com