set_current_exception_handler


set_current_exception_handler(fn)
      

Set the current exception handler function to fn and return void.

Fn takes a single argument that represent the exception currently being handled.

Return void.

Examples:


/*
The current exception handler is not active in the REPL.
To test this functions you should compile a script.
For example, compile the following scripts, run the executables and see how changing the
current exception handler affect the way error is reported:*/

// test1.sn
1 / 0

// Compile test1.sn to a standalone executable:
slogan> compile("test1", exe = true)

// Run from the OS shell:
$ ./test1 
//> *** ERROR -- Divide by zero
(/ 1 0)


// test2.sn
set_current_exception_handler(^(ex) showln("ERROR CAUGHT!!", ex))
1 / 0

// Compile test2.sn to a standalone executable:
slogan> compile("test2", exe = true)

// Run from the OS shell:
$ ./test2
//> "ERROR CAUGHT!!"#<divide-by-zero-exception #2>
      

Also see:

raise
error
abort


Core Module Index | Contents