better error handling for handler panics