Added a function to output the correct exception message