So, you wrote the program, started it in the debugger - everything is fine, everything is fine. Put in the workflow - falls. Moreover, in the most unexpected places.
What to do?
We start to think. Everywhere put try-catch ... the computing unit will be great to slow down. So, you need to make a debug version. So we enter
#define __TRY__DEBUG__
OK. Good. In suspicious places set
#ifdef __TRY__DEBUG__ try{ #endif
Oops. output function scattered in different places. Not good.
Exception class is born
class DebugException: exception {}
Oops number two. And what is stored in it?
So, we need what? output to file It is desirable all with what function at the moment of crash works.
Those. we need text data.
Yeah.
struct Obj{
So, we go further. In what to store, invented, we think how to get the whole thing from the object with which we work.
Obj * GetState () method is born; which is prescribed in each class.
We go further.
Now, attention is the question: where is the output to a file?
It is possible in the same place where the crash. Those. in the exception constructor ... Yeah, not good.
In the exception class, the printf method appears, outputting the entire object to a file.
main begins to take shape
#ifdef __TRY__DEBUG__ try{ #endif
So, and it would be nice to collect information about the system as a whole. This is how the view constructor is born.
As a result, the code increases by a factor of two, but in the case of a crash, you can find out who caused it, who was to blame.
')
pros
+ much less summary information than when logging. Especially if the test version worked fine for two days, and the third one crashed.
+ It is possible to collect absolutely complete information about the system at the time of the crash.
+ Does not affect the release version.
Minuses
- Completely different organization code functions. Since the variables declared in the try block are unknown in the catch block, they have to be declared at the beginning of the functions, forgetting about the elegance of the code.
- A lot of debugging code
- It may be that the reason that led to this state of the system is missing.