smarter exception handling