If you write more code, you will inevitably encounter unexpected or unknown errors. Unlike the Java pure oo advanced language, exception capture in C ++ is rarely used (it seems that foreigners like it very much, such as ogre and cegui are used ). Besides, this is not efficient. Therefore, when a program goes down, the log (for example, better debugging) or the memory dumping file (for example, core dump in Linux and mini dump in Windows) should be taken into account ). Here, we only provide a simple usage of minidump in Windows (it has never been used before, and this is what we learned from the main program ^_^ .. The generated DMP file can be analyzed by windbg. In this way, you can quickly locate errors.
# Ifdef Win32 <br/> // dump minidump in Windows environment <br/> # include <dbghelp. h> <br/> # pragma comment (Lib, "dbghelp. lib ") <br/> int write_dump (pexception_pointers extends tptr) <br/>{< br/> If (! Extends tptr) {return 0 ;}< br/> const int tempstrlen = 256; <br/> char filename [tempstrlen]; <br/>:: zeromemory (filename, tempstrlen ); <br/> systemtime effecime; <br/>: zeromemory (& systime, sizeof (systime); <br/>: getlocaltime (& systime ); <br/> sprintf_s (filename, tempstrlen ,". /guistudio_memdump _ % d. % d. % d _ % d. % d. % d. DMP ", <br/> policime. wyear, too ime. wmonth, too ime. wday, <br/> policime. whour, mongoime. wminute, policime. Wsecond); <br/> minidump_exception_information effectinfo; <br/>: zeromemory (& effectinfo, sizeof (effectinfo); <br/> effectinfo. predictionpointers = effectptr; <br/> effectinfo. clientpointers = false; <br/> using tinfo. threadid =: getcurrentthreadid (); <br/> handle hfile =: createfilea (filename, generic_write, 0, create_new, file_attribute_compressed, 0); <br/> :: minidumpwritedump (<br/>: getcurrentprocess (), <Br/>: getcurrentprocessid (), <br/> hfile, <br/> minidumpnormal, <br/> & cmdtinfo, null, null); <br/> :: closehandle (hfile); <br/> return 0; <br/>}< br/> # endif <br/> // proxy main <br/> int proxy_main (INT argc, char ** argv) <br/> {<br/> // your code... <br/>}< br/> // real main entry <br/> int main (INT argc, char ** argv) <br/> {<br/> int ret = 0; <br/> # ifdef Win32 <br/>__ try <br/> {<br/> # endif <br/> ret = proxy_m Ain (argc, argv); <br/> # ifdef Win32 <br/>__ compile T (write_dump (getexceptioninformation ())) <br/>{< br/> // we got an exception! <Br/> return-1; <br/>}< br/> # endif <br/> return ret; <br/>}< br/>