sichtbar machen
Dependencies: mbed
beispiel_fur_exceptionklassen/main.cpp@2:5fd21c59f63c, 2020-04-28 (annotated)
- Committer:
- kafka
- Date:
- Tue Apr 28 19:37:39 2020 +0000
- Revision:
- 2:5fd21c59f63c
- Parent:
- 1:18c470c81ce5
sichbar machen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kafka | 1:18c470c81ce5 | 1 | #include "exception.h" |
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 | using std::cin; |
kafka | 1:18c470c81ce5 | 7 | |
kafka | 1:18c470c81ce5 | 8 | int main(int argc, char const *argv[]) |
kafka | 1:18c470c81ce5 | 9 | { |
kafka | 1:18c470c81ce5 | 10 | int number; |
kafka | 1:18c470c81ce5 | 11 | std::string input; |
kafka | 1:18c470c81ce5 | 12 | const std::string bb; |
kafka | 1:18c470c81ce5 | 13 | cout << "let's begin with exceptions" << endl; |
kafka | 1:18c470c81ce5 | 14 | cout << "write a number, which is not even and greater than 23: "; |
kafka | 1:18c470c81ce5 | 15 | try |
kafka | 1:18c470c81ce5 | 16 | { |
kafka | 1:18c470c81ce5 | 17 | cin >> number; |
kafka | 1:18c470c81ce5 | 18 | if (!(number % 2)) |
kafka | 1:18c470c81ce5 | 19 | { |
kafka | 1:18c470c81ce5 | 20 | throw myexceptions(myexceptions::Error_Type::EVEN); |
kafka | 1:18c470c81ce5 | 21 | } |
kafka | 1:18c470c81ce5 | 22 | if(number < 23) |
kafka | 1:18c470c81ce5 | 23 | throw myexceptions(myexceptions::Error_Type::TOO_SMALL); |
kafka | 1:18c470c81ce5 | 24 | } |
kafka | 1:18c470c81ce5 | 25 | catch(const myexceptions& e) |
kafka | 1:18c470c81ce5 | 26 | { |
kafka | 1:18c470c81ce5 | 27 | std::cerr << e.what() << '\n'; |
kafka | 1:18c470c81ce5 | 28 | } |
kafka | 1:18c470c81ce5 | 29 | return 0; |
kafka | 1:18c470c81ce5 | 30 | } |