Fix EZP-22131: handle exceptions in legacy kernel callback

http://jira.ez.no/browse/EZP-22131

If an exception gets thrown in a legacy callback, the LegacyKernel cleanup code isn't called, and calling another callback will throw a runtime exception.