Fix EZP-22131: handle exceptions in legacy kernel callback

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.