Capture errors correctly