{{fbdoc item="title" value="ERR"}}---- Get or set the run-time error number {{fbdoc item="usage"}}## //result// = **Err**( ) //or// **Err** = //number// ## {{fbdoc item="desc"}} The ##**Err()**## function returns the ""FreeBASIC"" run-time error number (a 32 bit ##[[KeyPgLong|Long]]##) which can be set by the built-in statements and functions, or by the program through ##**Err = //number//**## or ##[[KeyPgError|Error]]##. Unlike ##[[KeyPgError|Error]]##, ##**Err = //number//**## sets the error number without invoking an error handler. See [[TblRuntimeErrors|Runtime Error Codes]] for a listing of the predefined runtime error numbers and their associated meaning. The program may use additional custom error numbers. ##**Err**## can always be used, even if QB-like error handling is not enabled. ##**Err**## is reset by ##[[KeyPgResume|Resume]]## and ##[[KeyPgResumenext|Resume Next]]##. Note: Care should be taken when calling an internal function (such as ##[[KeyPgPrint|Print]]##) after an error occurred, because it will reset the error value with its own error status. To preserve the ##**Err**## value, it is a good idea to store it in a variable as soon as the error handler is entered. Remark: Some procedures used in their function version return directly the error code (a 32 bit ##[[KeyPgLong|Long]]##). That is the case for: ##[[KeyPgBload|Bload]]##, ##[[KeyPgBsave|Bsave]]##, ##[[KeyPgClose|Close]]##, ##[[KeyPgFilecopy|FileCopy]]##, ##[[KeyPgGetjoystick|GetJoystick]]##, ##[[KeyPgGetmouse|GetMouse]]##, ##[[KeyPgImageInfo|ImageInfo]]##, ##[[KeyPgKill|Kill]]##, ##[[KeyPgOpen|Open]]##, ##[[KeyPgOpenCom|Open Com]]##, ##[[KeyPgOpenCons|Open Cons]]##, ##[[KeyPgOpenErr|Open Err]]##, ##[[KeyPgOpenLpt|Open Lpt]]##, ##[[KeyPgOpenPipe|Open Pipe]]##, ##[[KeyPgOpenScrn|Open Scrn]]##, ##[[KeyPgScreenres|ScreenRes]]##, ##[[KeyPgScreensync|ScreenSync]]##, ##[[KeyPgSetdate|SetDate]]##, ##[[KeyPgSetmouse|SetMouse]]##, ##[[KeyPgSettime|SetTime]]##. {{fbdoc item="ex"}} An example using QBasic style error handling (compile with -ex option) {{fbdoc item="filename" value="examples/manual/error/err1.bas"}}%%(freebasic) '' Compile with -lang fblite or qb #lang "fblite" On Error Goto Error_Handler Error 150 End Error_Handler: n = Err() Print "Error #"; n Resume Next %% An example using inline error handling (note: ##[[KeyPgOpen|Open]]## can also return its own error status when called as a function) {{fbdoc item="filename" value="examples/manual/error/err2.bas"}}%%(freebasic) '' compile without -e switch dim filename as string do line input "Input filename: ", filename if filename = "" then end open filename for input as #1 loop until err() = 0 print using "File '&' opened successfully"; filename close #1 %% {{fbdoc item="diff"}} - Error numbers are not the same as in QB. {{fbdoc item="see"}} - ##[[KeyPgOnerror|On Error]]## - ##[[KeyPgError|Error]]## - [[ProPgErrorHandling|Error Handling]] - [[TblRuntimeErrors|Runtime Error Codes]] {{fbdoc item="back" value="CatPgError|Error Handling Functions"}}