Added exception handler to stats gathering