exporting functions which raise exceptions

Manuel M. T. Chakravarty chak at cse.unsw.edu.au
Wed Jun 12 21:28:26 EDT 2002

Alastair Reid <reid at cs.utah.edu> wrote,

> Suppose I foreign export (or wrap) a Haskell function and that
> function raises an exception, calls exit or raises an error.  
> How should this be reflected on the C side?
> In a batch-mode system (ghc, runhugs, nhc), we need to call a
> no_return function like exit but should it always be exit or should
> there be a way for an application to register an alternative function?
> (e.g., If my Basic interpreter makes a foreign function call into
> Haskell, I'd like an error in Haskell to bring me back to the Basic
> REPL not to quit my program).
> In an interactive system (ghci, Hugs), the right thing to do seems to
> be to return to the interpreters REPL.

We discussed this before and agreed that any uncaught
exception in a call back from C to Haskell land aborts the
program.  If the exceptions is to be propagated from the
call back to the main application, it is the FFI user's
responsibility to arrange this.

(I believe that this is actually noted somewhere in the
current spec, if it isn't it should, though.)


More information about the FFI mailing list