Refactored internal exception handler