Repository navigation
On Error
Home › Error Handling Functions › On Error
Sets a label to jump to when a runtime error happens; On Error Goto 0 turns it off.
On [Local] Error Goto labellabel
On Error triggers a jump to an error handler when an error occurs. Such errors can be triggered by built-in statements such as Open, or when the Error statement is used.
Note: The error checking for built-in statements is only enabled if the program is compiled with one of the -e, -ex or -exx options. On Error remains working with Error even when none of these options are used.
On Local Error can be used to specify a local error handler inside a procedure. This allows for specialized per-procedure error handling and will override the global error handler, if any.
Without Local, the handler must be in the main part of the module.
Remark: Presently, the Local clause is ignored by the compiler.
On Error Goto 0 deactivates the current error handler.
- QB has no LOCAL clause and requires the label to be in the main part of the module.
on error goto errorhandler
error 24 '' simulate an error
print "this message will not be seen"
errorhandler:
dim as int32 n = err
print "Error #"; n; "!"
end'' compile with: tiko onerror.tiko -ex
function hFileExists( byref filename as string ) as boolean
dim as long f = freefile
on local error goto exitfunction
open filename for input as #f
close #f
return true
exitfunction:
return false
end function
print "File exists: "; hFileExists( command( 1 ) )
on error goto errhandler
error 1234
print "not seen: an error handler cannot return here"
end 0
errhandler:
print "error number: " + str( err ) + " at line: " + str( erl )
end 1Category: Error Handling Functions
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Home
- What Is tiko-lang
- Quick Start
- Installing on macOS
- Debugging
- Feature Index
- Compatibility
- FAQ
- AI Cheatsheet
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Time Zones
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing