Re: catch native crash
Paul Geisler wrote:
Hello,
any idea how to catch a crash in JNI / JNA adapted native code? I
have
to use large code collections (codecs etc.) that are crash prone by
design (eg. they have to handle damaged media files etc.). So in
case
of a trap/crash, the JVM should exit native code, throw an (maybe
unprecise) exception and go on as usual.
Is there any (maybe native) library to implement this?
A vague thought: if you wrapped the existing JNI calls with C++ that
catches the SegV (or whatever the crash amounts to) as an exception,
and then reports that exception to the JVM nicely, you'd have some
chance of contusing normal processing. You'd very likely have a
memory leak, since the unwinding of the stack would lose track of any
memory allocated by the discarded stack frames, but if you're lucky,
it's no worse than that (i.e. memory hasn't been scribbled over, the
heap hasn't been used up, the number of files left open doesn't use up
your process's quota, etc.)
A much more robust solution is, as others have suggested, to run the
questionable code in a different process, so that after a crash its
resources can be cleaned up by the OS.