Is it posible to write a try catch block to catch every possible error ?
I dont want to throw nothing, I want that program itself tells me what is happen.
I have seen the 'include <exception>' but my program keeps on having abnormal ending (The program has detected a problem and etc... Windows message)
Can I write a 'global' error control ? That is to say, I want to detect all posible errors.
I have catch (exception& e), but I dotn catch anything.
I remember the old VB 6 and its on error goto blabla and err.code
Is there something similar in C++?
How affect the exceptions control to the performance of the program ?
You could just use a debugger. It will normally tell you what line of code caused the crash, variable values, threads running and it will show you the stack (functions called starting with main).
If you really wanted to, you could put a try catch block around the entire body of main, but if the program segfaults or has some other irrecoverable error, it will crash regardless.
So, is not any way to avoid the final user has crashes ?
I simply would want a more elegant exit (in example a custom dialog)
So, how many situations can I catch ? Any link to a list of it ?
Thanks
I dont want to throw nothing, I want that program itself tells me what is happen.
I some cases, you will need to throw an exception.
Some standard features such as new, and vector throw exceptions themselves, leaving you to catch them. If you create a function that has the potential to cause a error, then you may want to throw an exception from that function.
C++ can't do everything for you; you need to do somethings yourself.
But you can still catch exceptions and display a message box. Use the exception::what() function to get an error message. Just remember not to use try and catch blocks around code which definitely won't throw, as it has a performance overhead.