caching: write the log even when an exception is thrown
caching: move pragma check after scope checking