Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 1:18c470c81ce5, committed 2020-04-21
- Comitter:
- kafka
- Date:
- Tue Apr 21 18:37:00 2020 +0000
- Parent:
- 0:e0dea4ed78aa
- Commit message:
- aufgabe
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beispiel_fur_exceptionklassen/exception.h Tue Apr 21 18:37:00 2020 +0000 @@ -0,0 +1,40 @@ +#include <exception> +#include <iostream> + +using std::cout; +using std::endl; + +class myexceptions : public std::exception +{ + public: + enum class Error_Type {EVEN, TOO_SMALL}; + private: + Error_Type error_type_; + public: + myexceptions(Error_Type error); + myexceptions(myexceptions const &var); + virtual const char *what() const noexcept; + ~myexceptions(); +}; + +myexceptions::myexceptions(Error_Type error) : error_type_ (error) +{ +} + +myexceptions::~myexceptions() +{ +} + +const char* myexceptions::what() const noexcept +{ + switch (error_type_) + { + case Error_Type::EVEN: + return "error: number is even"; + case Error_Type::TOO_SMALL: + return "error: number is too small"; + default: + return NULL; + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/beispiel_fur_exceptionklassen/main.cpp Tue Apr 21 18:37:00 2020 +0000 @@ -0,0 +1,30 @@ +#include "exception.h" +#include <iostream> + +using std::cout; +using std::endl; +using std::cin; + +int main(int argc, char const *argv[]) +{ + int number; + std::string input; + const std::string bb; + cout << "let's begin with exceptions" << endl; + cout << "write a number, which is not even and greater than 23: "; + try + { + cin >> number; + if (!(number % 2)) + { + throw myexceptions(myexceptions::Error_Type::EVEN); + } + if(number < 23) + throw myexceptions(myexceptions::Error_Type::TOO_SMALL); + } + catch(const myexceptions& e) + { + std::cerr << e.what() << '\n'; + } + return 0; +} \ No newline at end of file