Fixing wrong exception handling implementenion