Improved error handling framework