SML# Document Version 4.0.0
29 SML# Run-time data management

29.3 Effect of unwind jumps

SML# and C/C++ provides jumps that unwinds call stack. In SML# and C++, exceptions are provided. In C, setjmp and longjmp are provided. These unwind jump mechanism can be used in combination with SML#’s callback functions. Unwind jumps has the following properties:

  1. 1.

    SML#’s exception handling mechanism is implemented through Itanium ABI, similarly to C++’s exception mechanism. Therefore, cleanup handlers may be invoked by SML#’s exceptions. For example, destructors of C++ local variables are executed appropriately when callback SML# function raises an exception.

  2. 2.

    Exceptions raised by SML#’s raise expression can be handled only by SML#’s handle expression. The handle expression only handles SML# exceptions and hence it is not able to handle other kind of unwind jumps.

  3. 3.

    If SML#’s exception is not caught by any handle expression, the program aborts.

  4. 4.

    C++ and SML# exceptions works independently of each other with SML# callback functions.

  5. 5.

    C’s setjmp and longjmp also work with SML# callback functions. It is not valid to create any loop in a SML# program by using setjmp and longjmp.