Catch C++ errors and do proper error reporting