fixing handling of exceptions

fixing handling of exceptions