Fix EZP-22131: handle exceptions in legacy kernel callback

http://jira.ez.no/browse/EZP-22131

Catches exceptions in legacy callbacks, and performs the cleanup task before throwing it again.