Better error handling for C++