Fix exception handling in test