Jump to content
Sign in to follow this  

Error handling idea

Recommended Posts


My problem was not having error messages up on a deep, deep function call stack. Using plain @error was problematic.

I quickly made an interface for exception-like error handling.

There isn't any real code or implementations yet, it's just a raw interface I figured on a bus trip.

_errorCreate( $msg ) - Create global error id. Returns error id.

_errorRaiseMsg( $msg ) - Raise general error with custom message.

_errorRaise( $id ) - Raise defined error

_errorCatch( $id ) - Catch error. If id is null, catch any error. Returns boolean whether error was caught.

_errorCaughtMsg() - Returns caught error message.

_errorCaughtId() - Returns caught error id.

_errorIs() - Returns boolean whether there's an error.

Example use:

; Create custom error id
Global $ERR_SOMEBAD = _errorCreate( "Something bad happened!" )


func main()
    ; Expect something behind foo() to raise an error
    if _errorCatch($ERR_SOMEBAD) Then
        MsgBox(0,"Specific error!", _errorCaughtMsg())
    ElseIf _errorCatch()
        MsgBox(0,"Unknow error!", _errorCaughtMsg())
        ; No error

func foo()
    if _errorIs() then Return
    ; this will not be executed because badFunction() caused error

func badFunction()

    ; Would also work:
    ;_errorRaiseMsg( "this is a general error")

After a catch the error is erased so that no other function can catch it anymore.

Edited by amokoura

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.