fix NPE when an exception is thrown