Handle uncaught errors instead of crashing