Safe error type switch

Ashamed...
Simplified type conversion
Merge pull request #65 from riobard/fix/typeswitch

Safe error type switch