Adding log messages when exceptions occur.