Detailed explanation and function of exception handling in C language or C++
This article mainly explains "the detailed explanation and function introduction of exception handling in C language or C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "C language or C++ exception handling and its role in the introduction" bar!
Catalogue
Overview
Exception handling
Exception handling mechanism
The function declaration specifies the exception
Practice
Case one
Case two
Overview
As a programmer who writes Bug professionally and changes bug one day to another week. It is very important to learn how to handle exceptions. We should consider not only the ideal situation where there is no error, but also the situation when there is an error.
Debug can help us find and eliminate errors as soon as possible. Error category:
Grammatical error
Running error
Logic error
Exception handling
When designing the program, various unexpected situations that may occur when the program is running are analyzed in advance, and the corresponding processing methods are customized. Exception handling refers to the handling of runtime errors and other exceptions.
When there is no exception handler, there is an exception and the program can only be terminated. Set the exception handling mechanism, run an exception, the flow of the program will be transferred to the exception handling code segment handling. The user can specify any processing.
Take an example where the divisor is 0:
# include using namespace std;template T Div (T x, T y); int main () {/ / declare variables int x, y; double x1, y1; / / assign cin > > x > > y; cin > > x1 > > y1; / / output quotient cout