I'm trying to catch a runtime error. When I run my program under certain circumstances I get a box which tells me that there has been a 'Runtime error' though when I add the below to my error handler, it doesn't seem to catch the error.
If I use the catch(...), this works. It catches an error though I can't see what it is. If my system is telling me that I have a runtime error then why can't I catch it? Is there a way to resolve this? Thanks
Hi
I can't actually put the code up. I'm not really interested in fixing that, what I'm trying to do is catch all kinds of errors which could appear. So I am using this error to determine how to resolve something like this.
I've tried the below already. Maybe I'm missing another type of error? I'm not sure.
If you take a look at the std::runtime_error class you will see that it only has 4 direct sub classes and non of those are sub classed. So unless your exception is a runtime exception (i.e. of the type specified by the 4 classes or runtime_error), then runtime_error is not able to catch that exception. http://www.cplusplus.com/reference/stdexcept/runtime_error/
You are most likely coming from a java background where java.lang.RuntimeException can be used to catch most runtime exceptions, but in C++, it is a bit different