small improvement to exception handling