I am developing an iOS application that has recently grown on a large C ++ base. C ++ is not my forte and I'm upset about exceptions. What I'm looking for is a way to get the stack path to the site of the (not processed) exception. I will say that the “unprocessed” qualifier is optional; I would agree to crack any exception as a last resort, although ideal exceptions are not handled.
What I am getting now is useless. Assuming I don't have matching exception handlers above the call, and I'm doing something like
std::vector<int> my_vector; my_vector.at(40) = 2;
The application will be broken down into main()
, and I will get a log message that says: "terminate called throwing exception". Not healthy.
Putting the common try / catch blocks above in callstack doesn't help either, as the column expands during exception handling to the point of the catch block, leaving me unaware of the actual origin of the exception. This also applies to providing my own terminate_handler
. Statements are more useful, but they require me to anticipate error conditions to some extent, which I cannot always do. I would still like the debugger to be able to go in even if an unforeseen exception makes it behind my anticipatory assert()
s.
What I want to avoid is to wrap all calls that might throw an exception in the try / catch block to get a stack trace to the error. At runtime, I'm really not interested in catching these exceptions. When they occur, it means that there is a fatal flaw in the execution of the program, and there is no way that this can continue in normal mode. I just want to be notified so that I can identify the cause and fix the problem so that it does not recur.
In Objective-C, I can put a symbolic breakpoint on objc_exception_throw
, and anytime I screw something, I immediately break execution and get a nice stack trace so that I know where the problem is. Very helpful.
I understand that this behavior is really only useful because of the philosophical difference in handling exceptions between the two languages. Objective-C exceptions are intended only to indicate fatal errors. The task of routine error handling is performed using error return codes. This means that any Objective-C exception is a great candidate for a breakpoint for the developer.
C ++ seems to be used for Exception. They are used to handle both fatal errors and routine errors (at least in the third-party libraries that I use). This means that I might not want to break into every exception thrown in C ++, but I still find utility if I cannot break only exceptions without handling.