# crash_routine

Definition: | crash_routine(integer rid)
Description: | Specify a function to be called when an error takes place at run time. rid: the routine_id of the function to invoke.
pwa/p2js: | Not (yet) supported.
Comments: | The supplied function should accept a single parameter, which is currently always 0. Invoking crash_routine() adds a new function to a list of routines to execute upon a crash. The routines defined first are executed last. If a crash routine returns anything other than 0, the remaining routines in the chain are skipped. Note that, unlike Euphoria, passing a rid of -1 clears the list. Be aware that crash_routine(routine_id("mis_spelt_name")) has the same effect. crash routines are not full fledged exception handlers (unlike try/catch), and they cannot resume execution. However, they can read the generated crash file, and might perform any action, including restarting the program.
Example: |
    function report_error(integer /*dummy*/)
        mylib:email("maintainer@remote_site.org", "ex.err")
        return 0
    end function
    crash_routine(routine_id("report_error"))
Implementation: | via :%pCrashRtn in builtins\VM\pDiag.e (an autoinclude) - be warned however it is low-level complicated stuff that you do not need to know.
See Also: | try/catch, abort, crash_file, debugging and profiling