Improved exception logging