using exception instanceof check instead of error codes