PAHMA-964: Ensure session is released when there is an exception.