add a global error handling method to catch exceptions