fixing handling of exceptions