Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "My_Exeption.h"
- #include <iostream>
- #include <cctype>
- #include <regex>
- #include <exception>
- int fun1() throw (exeption_n)
- {
- bool fl = false;
- int x = 0;
- cin >> x;
- fl = true;
- if (!cin.good() || cin.peek() != '\n')
- {
- throw exeption_n(2);
- }
- if (x<0)
- {
- throw exeption_n(3);
- }
- return x;
- }
- char* fun2() throw (exeption_n)
- {
- bool fl = false;
- char* str;
- str = new char[80];
- fgets(str,sizeof(str),stdin);//ограничиваем ввод размера нашего буфера
- fl = true;
- for (int i = 0; i<sizeof(str); i++)
- {
- if (false == regex_match(str, regex("[[:alpha:]]+")))
- {
- throw exeption_n(1);
- }
- }
- return str;
- }
- char* fun3()throw(exeption_n)
- {
- bool fl = false;
- char *str;
- str = new char[80];
- for (int i = 0; i < sizeof(str); i++)
- {
- if (!((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) || (str[i] >= '0'&&str[i] <= '9'))
- throw exeption_n(4);
- }
- return str;
- }
- exeption_n::exeption_n(int _number)
- {
- this->number = _number;
- switch (_number)
- {
- case 1:
- {
- this->name = " Ожидался ввод только английских букв";
- break;
- }
- case 2:
- {
- this->name = " Ожидался ввод только целочисленного типа";
- break;
- }
- case 3:
- {
- this->name = " Введено отрицательное число";
- break;
- }
- case 4:
- {
- this->name = "Введите число или букву";
- break;
- }
- case 88:
- {
- this->name = " Необработанное исключение";
- break;
- }
- case 77:
- {
- this->name = " error";
- break;
- }
- }
- }
- exeption_n::exeption_n(const exeption_n & tmp)
- {
- this->number = tmp.number;
- this->name = tmp.name;
- }
- exeption_n::~exeption_n()
- {
- }
- void operator << (std::ostream & os, exeption_n & tmp)
- {
- os << "Код исключения:" << tmp.number << endl << "Ошибка:" << tmp.name << endl << endl;
- }
- char enter_int_char()
- {
- bool fl = false;
- char* str;
- str = new char[80];
- do {
- try
- {
- str= fun3();
- fl = true;
- }
- catch (exeption_n &ex)
- {
- cout << ex;
- fl = false;
- cin.clear();
- rewind(stdin);
- cin.sync();
- }
- catch (...)
- {
- cout << "catch(...)" << endl;
- fl = false;
- cin.clear();
- cin.sync();
- }
- } while (fl == false);
- return *str;
- }
- int enter_int()
- {
- bool fl = false;
- int k = 0;
- do
- {
- try
- {
- k = fun1();
- fl = true;
- }
- catch (exeption_n &ex)
- {
- cout << ex;
- fl = false;
- cin.clear();
- rewind(stdin);
- cin.sync();
- }
- catch (...)
- {
- cout << "catch(...)" << endl;
- fl = false;
- cin.clear();
- cin.sync();
- }
- } while (fl == false);
- return k;
- }
- char* enter_char()
- {
- bool fl = false;
- char* str;
- str = new char[80];
- do
- {
- try
- {
- str = fun2();
- fl = true;
- }
- catch (exeption_n &ex)
- {
- cout << ex;
- fl = false;
- cin.clear();
- rewind(stdin);
- cin.sync();
- }
- catch (...)
- {
- cout << "catch(...)" << endl;
- fl = false;
- cin.clear();
- rewind(stdin);
- cin.sync();
- }
- } while (fl == false);
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement