C++ implementation: exception aware