[CPP] Try-Catch Clause
As java, we need a try-catch block in c++. The universal format of try-catch is
try{
program-statements
} catch (exception-declaration) {
handler-statements
} catch (exception-declaration) {
handler-statements
} //...
Standard exception
C++ standard library defines a set of classes which is used for exception. They are defined in the following 4 header files:- exception: defines the most general kind of exception class. It communicates only that an exception occurred but provides no additional information.
- stdexcept: defines several general-purpose exception classes.
- new: defines the bad_alloc exception type.
- type_info: defines the bad_cast exception type
stdexcept:
- exception: the most general kind of problem
- runtime_error: problems that can be detected only at run time
- range_error: runtime_error: result generated outside the range of values that are meaningful
- overflow_error: runtime_error: computation that overflowed
- underflow_error: runtime_error: computation that underflowed
- logic_error: Error in the logic of the program
- domain_error: logic error: argument for which no result exists
- out_of_range: logic error: used a value outside the valid range
评论
发表评论