Logging and exception handling