Improved exception handling to be able to catch by actual type.