Using anomalous and return value 1. Use the return value to handle error requires a strict programming style of programmers, and the programmer has this habit, which is very undesirable. 2. The correct exception handling is a common sense in C . An exception can make the program code and the error handling code separately by issuing an error signal, and will not let the program ignore the error. 3. Do you have to know which error handling method is used, the return value or throw an exception. If you don't know, then your program must have a problem. 4. An exception is based on each thread and processes; exceptions cannot be ignored by threads, must be processed; unprocessed exceptions will end, not just threads; abnormal processing is released when released in the release stack Stack objects, thus avoiding the vulnerability of resources; exception handling requires a lot of additional operations, making it not suitable for frequently running. In detail, Catch block has some overhead, but the TRY block has little overhead; so there is only a lot of abnormal operation overhead when thriving an exception; you can throw any type of unusual object, but Does not include integers. 5. The return value can indicate the normal and abnormal functions, but it cannot block the continuation of the thread; the return value is easily ignored; the return value is an integer in the typical case, usually mapped to a predefined value; Return value can be efficiently transmitted and received; 6. All non-error status information should be used to return value 7. Return values can be ignored at most cases without problems 8. Errors in the loop Processing must be fast, because of an extra overhead, in order to get better performance, use the return value is a better choice. In this case, if you really want to use an exception, you can create a function to convert the return value is not an abnormal. 9. Used in an error in the intermediate language module. 10. Using the error handling mechanism for Windows API. Use the setLastError to set the error code and detect this error code via getLastError. 11. From the point of view of C abnormal processing, the fault should be considered an error. 12. You must use the / eha debugger option to swear the operating system exception using the C exception operating mechanism. 14.Windows structure exception handler: Using _Try, _except, _final, _leave keyword, and raiseexception API function; supported by Windows, not suitable for other operating systems; do not processes resolution of C objects; Out, you can also be thrown as a result of the raiseException function. 15.c Abnormalities: Use Try, Throw and Catch, etc. Keywords; only by C language; process the resolution of C objects; any type of C object can be thrown. Abnormal objects can be derived from standard abnormal basic classes, or derived from any class, or they can also be built-in types; as the result of the Throw statement is thrown. 16. Visual C uses the structural exception handling mechanism to implement C exceptions. 17. The structural exception handling cannot handle the resolution of the object, so you should use C exceptions in the C program. However, because C exceptions cannot handle hardware and operating system exceptions, your program needs to convert structural anomalies to C exceptions. 18. In order to properly handle hardware and operating system exceptions, you can create your own anomaly classes and use the _SET_SE_TRANSLATOR function to install a converter for the C exception to the C exception. 19. Do not rush to the structural exceptions that cannot be recovered. 20. The cost of using an abnormality in the abnormality is not very small, and this can indeed improve performance.
21. The most important part of the abnormal strategy is actually a strategy. Don't make up afterwards. 22. Abnormal roller rules: The flopprocessor is provided in order; if the flop processor rushes the same type or points to the same type to throw the object, it should be exception. If the roller processor rises a common base class or points to a pointer to the object, it should be abnormal; a omitted processor rushes to any type of exception, so it is always in the last . 23. Define an exception base class to handle the exception thrown by the program code. Class CProgramException: CPROGRAMEXCEPTION (const_exstring & _what_arg): Exception (_WHAT_ARG) {}}; using the CPROGRAMEXCEPTION class makes exception handling more simple because it can be processed by processing this base class. Exception. If necessary, you can also use additional member data to fully describe specific issues. 24. Use auto_ptr or a similar pointer to the dynamic allocation of local variables from the dynamic allocation of local variables to release resources: Void LeakFreeFunction (int Arg) {auto_ptr
(10) Re-throwing this exception, so that the advanced function can handle this exception, especially if the current function cannot be completely solved. You can reap out the same exception object or throw a new anomaly object. 29. and / eHA relative to synchronous abnormalities (/ EHS), not / gx. / GX is actually a simplified form of / EHSC. / Gx indicates that the compiler should assume that the function of the extern "C" does not throw a C exception, and / EHS throws. 30. Record an exception for the user and calling environment. Typically, the abnormality object type is used to notify the invoked environment, and the description of the problem is used to notify the user. 31. Visual C By default, New and Malloc do not throw exceptions for errors, but you can install a processor using _SET_NEW_HANDLER, let NEW thrown an exception for errors. You can also let Malloc use the same processor by calling _SET_NEW_MODE. #include
INT NewHandler (SIZE_T SIZE) {Throw Bad_alloc ("Operator New Couldn't Allocate Memory); Return 0;}
Int apientry Winmain (Hinstance Hinstance, LPSTANCE HPREVINSTANCE, LPSTANCETANDLINS, INT NCMDSHOW) {_SET_NEW_HANDLER (NewHandler); _SET_NEW_MODE (1); // use newhandler for malloc as well ...}
32. If there is no set of NEW to return null values in the existing code, then you should always throw an exception when the New is wrong. 33. The floating point and integer are different. By default it does not have an exception, but there will be a very strange value "1. # info" (it indicates that this value is not a number). To make the problem of detecting floating point numbers, you should use the following code to let the floating point number error throw an exception. #include