Advertisement
Guest User

Untitled

a guest
May 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #ifndef EXCEPTIONS_H
  2. #define EXCEPTIONS_H
  3.  
  4. #include <exception>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. class BaseException : public exception
  10. {
  11. public:
  12. BaseException() : msg(""), func(""), file(""), line(0){}
  13.  
  14. explicit BaseException(const char* error, const char* funcName, const char* fileName, int lineError):msg(error), func(funcName), file(fileName), line(lineError){}
  15.  
  16. virtual const char* what()
  17. {
  18. std::string message = "";
  19.  
  20. message += msg;
  21. message += ". Файл: ";
  22. message += file;
  23. message += ". Строка: ";
  24. message += std::to_string(line);
  25. message += ". Функция: ";
  26. message += func;
  27.  
  28. return message.c_str();
  29. }
  30. const char* get_func() const
  31. {
  32. return func;
  33. }
  34. protected:
  35. const char* msg;
  36. const char* func;
  37. const char* file;
  38. const int line;
  39. };
  40.  
  41. class NullPointerException: public BaseException
  42. {
  43. public:
  44. explicit NullPointerException(const char* funcName, const char* fileName, int lineError)
  45. : BaseException("Null Pointer Exception at", funcName, fileName, lineError){}
  46. };
  47. #endif // MY_EXCEPTION_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement