In writing a ctypes demo, poor sheppy just took down his browser because of an Obj-C exception. This makes me feel bad. (Note that he was calling C code in the Mac CF library, but it happened to call into Obj-C code further in.) So I'm thinking -- what if, when declaring a function, you could say library.declare(ctypes.default_abi, ctypes.exceptions, ...) to say "enable exception support", and then when doing the ffi_call() itself, ctypes wraps it in a try/catch. And propagates it back to script as a JS exception. This try/catch bit could live in a stub function, in a separate source file, for which exceptions are compile-time enabled. bsmedberg also suggests that, on Windows, we could wrap all code (even C) with __try/__catch, to catch all crashes. That would be pretty cool. If Obj-C and C++ (and Windows C) exceptions are all identical in implementation, then we could even just do it by default. This also requires, I think, that libffi support exceptions. On linux/x86, it does. I have no idea about the other plats.
P3, really nice to have, but I suspect this is a bit of work.
Priority: -- → P3
Note that for Obj-C exceptions you'd need @try / @catch: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html#//apple_ref/doc/uid/20000059 (also you'll need to be in an Obj-C file). try / catch will only catch C++ exceptions. __try / __catch on Windows will catch all crashes.
You need to log in before you can comment on or make changes to this bug.