Catch exceptions in handler functions