Writing exception-safe classes