checking for an error before converting it to a C++ string, which will
cause an exception