I set out to do a simple task: Catch an H5::Exception and capture its error message in a string.
I already know what the error is (because I introduced it for testing): I’m accessing a group that does not exist.
I can see “Object not found” on the console. I would like to have the string “Object not found” in my code please. How do I do that?
I tried to call H5::Exception::getDetailMsg()
, but that gives me a completely useless H5Gopen2 failed
.
The method H5::Exception::getMinorString
looked promising! Turns out, this method needs a minor number.
First question: Why is this a member function if it doesn’t reference anything in the Exception object? Why isn’t it just static? What is even the point of this function?
Second question: How do I get the minor error number? There are no member functions in the Exception class that give me this information. I find this bewildering, because apparently, this object was constructed during error handling, but did not bother to save the actual error state.
I then set out to find the minor error code in the C API, but I could not find a simple function that returns it. Why not?
Then I set out to “walk” the error stack to get my minor code from there. To my dismay, I find out the error stack does not survive stack unwinding. Presumably, some H5:: object 's destructor calls API functions that destroy the error stack.
To summarize:
getDetailMsg() is useless.
getMinorString() needs a minor code.
Getting the minor code is impossible unless
Therefor, getting a usable error message is impossible.
Has anybody of the authors of the C++ API actually ever tried to use the C++ API? The more I use it, the more I start to doubt that.
How are you supposed to do error handling in C++?