sichtbar machen
Dependencies: mbed
beispiel_fur_exceptionklassen/exception.h@1:18c470c81ce5, 2020-04-21 (annotated)
- Committer:
- kafka
- Date:
- Tue Apr 21 18:37:00 2020 +0000
- Revision:
- 1:18c470c81ce5
aufgabe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kafka | 1:18c470c81ce5 | 1 | #include <exception> |
kafka | 1:18c470c81ce5 | 2 | #include <iostream> |
kafka | 1:18c470c81ce5 | 3 | |
kafka | 1:18c470c81ce5 | 4 | using std::cout; |
kafka | 1:18c470c81ce5 | 5 | using std::endl; |
kafka | 1:18c470c81ce5 | 6 | |
kafka | 1:18c470c81ce5 | 7 | class myexceptions : public std::exception |
kafka | 1:18c470c81ce5 | 8 | { |
kafka | 1:18c470c81ce5 | 9 | public: |
kafka | 1:18c470c81ce5 | 10 | enum class Error_Type {EVEN, TOO_SMALL}; |
kafka | 1:18c470c81ce5 | 11 | private: |
kafka | 1:18c470c81ce5 | 12 | Error_Type error_type_; |
kafka | 1:18c470c81ce5 | 13 | public: |
kafka | 1:18c470c81ce5 | 14 | myexceptions(Error_Type error); |
kafka | 1:18c470c81ce5 | 15 | myexceptions(myexceptions const &var); |
kafka | 1:18c470c81ce5 | 16 | virtual const char *what() const noexcept; |
kafka | 1:18c470c81ce5 | 17 | ~myexceptions(); |
kafka | 1:18c470c81ce5 | 18 | }; |
kafka | 1:18c470c81ce5 | 19 | |
kafka | 1:18c470c81ce5 | 20 | myexceptions::myexceptions(Error_Type error) : error_type_ (error) |
kafka | 1:18c470c81ce5 | 21 | { |
kafka | 1:18c470c81ce5 | 22 | } |
kafka | 1:18c470c81ce5 | 23 | |
kafka | 1:18c470c81ce5 | 24 | myexceptions::~myexceptions() |
kafka | 1:18c470c81ce5 | 25 | { |
kafka | 1:18c470c81ce5 | 26 | } |
kafka | 1:18c470c81ce5 | 27 | |
kafka | 1:18c470c81ce5 | 28 | const char* myexceptions::what() const noexcept |
kafka | 1:18c470c81ce5 | 29 | { |
kafka | 1:18c470c81ce5 | 30 | switch (error_type_) |
kafka | 1:18c470c81ce5 | 31 | { |
kafka | 1:18c470c81ce5 | 32 | case Error_Type::EVEN: |
kafka | 1:18c470c81ce5 | 33 | return "error: number is even"; |
kafka | 1:18c470c81ce5 | 34 | case Error_Type::TOO_SMALL: |
kafka | 1:18c470c81ce5 | 35 | return "error: number is too small"; |
kafka | 1:18c470c81ce5 | 36 | default: |
kafka | 1:18c470c81ce5 | 37 | return NULL; |
kafka | 1:18c470c81ce5 | 38 | } |
kafka | 1:18c470c81ce5 | 39 | |
kafka | 1:18c470c81ce5 | 40 | } |