added code to deal with diff kinds of exceptions