Move exception handler to main