c_-_c_exception_handling:class_exceptions
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
c_-_c_exception_handling:class_exceptions [2017/10/12 10:36] – created peter | c_-_c_exception_handling:class_exceptions [2020/07/15 09:30] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== C - C++ Exception Handling - Class Exceptions ====== | ====== C - C++ Exception Handling - Class Exceptions ====== | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | class forgetcode | ||
+ | { | ||
+ | public: | ||
+ | char Error[80]; | ||
+ | | ||
+ | forgetcode() { | ||
+ | cout<<" | ||
+ | } | ||
+ | |||
+ | void display() | ||
+ | { | ||
+ | cout<<" | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | |||
+ | int main() | ||
+ | { | ||
+ | int i; | ||
+ | |||
+ | try { | ||
+ | cout << "Enter a positive number: "; | ||
+ | cin>> | ||
+ | |||
+ | if(i<0) | ||
+ | throw forgetcode(); | ||
+ | else | ||
+ | cout<<" | ||
+ | } | ||
+ | catch (forgetcode f) { | ||
+ | f.display(); | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
c_-_c_exception_handling/class_exceptions.1507804574.txt.gz · Last modified: 2020/07/15 09:30 (external edit)