Hello,
I have been seeing SysError in <SomeClass::Method()> error message from time to time. How can we catch it ? I cannot find any SysError class anywhere.
Is it actually cacheable ?
Hello,
I have been seeing SysError in <SomeClass::Method()> error message from time to time. How can we catch it ? I cannot find any SysError class anywhere.
Is it actually cacheable ?
Hi @meyerma,
SysError is not a class, but a function defined in TError.h.
The ROOT errors don’t use any exceptions, so there is nothing to catch. But if you want, you can change the error handler with TError::SetErrorHandler() to something that throws exceptions.
Here is a little example:
void MyErrorHandler(int level, Bool_t abort, const char *location, const char *msg)
{
if (level == kSysError) {
std::cout << "it's a SysError!" << std::endl;
throw std::runtime_error("ROOT had a SysError.");
}
DefaultErrorHandler(level, abort, location, msg);
}
void demo()
{
auto oldHandler = SetErrorHandler(MyErrorHandler);
SysError("demo", "I am error");
// Don't forget to reset the error handler
SetErrorHandler(oldHandler);
std::cout << "Ending the demo." << std::endl;
}
I would probably only change the error handler only during the part of the code where you want to catch the SysError. Just to control the side effects of that surgery ![]()
Cheers,
Jonas
@jonas This is exactly what I need ![]()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.