Reworked exception handling code to add more precise causes
Applied changes following mpollack's comments