c_-_c_exception_handling:throwing_exceptions
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
c_-_c_exception_handling:throwing_exceptions [2017/10/12 10:37] – created peter | c_-_c_exception_handling:throwing_exceptions [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== C - C++ Exception Handling - Throwing Exceptions ====== | ====== C - C++ Exception Handling - Throwing Exceptions ====== | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using std::cin; | ||
+ | using std::cout; | ||
+ | using std::endl; | ||
+ | using std:: | ||
+ | |||
+ | class DivideByZeroException : public runtime_error | ||
+ | { | ||
+ | public: | ||
+ | | ||
+ | }; | ||
+ | |||
+ | |||
+ | double quotient( int numerator, int denominator ) | ||
+ | { | ||
+ | throw DivideByZeroException(); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | |||
+ | int main() | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | double result = quotient( 1, 1 ); | ||
+ | cout << "The quotient is: " << result << endl; | ||
+ | } | ||
+ | catch ( DivideByZeroException & | ||
+ | { | ||
+ | cout << " | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
c_-_c_exception_handling/throwing_exceptions.1507804673.txt.gz · Last modified: 2020/07/15 09:30 (external edit)