General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
1.9 KiB

  1. #pragma once
  2. #include "gp_config.hpp"
  3. #include <new>
  4. namespace gp{
  5. class runtime_error{
  6. protected:
  7. const char* what_str;
  8. public:
  9. runtime_error(const char* what)
  10. : what_str{what}
  11. {}
  12. runtime_error()
  13. {
  14. what_str = "an unknown error has occured";
  15. }
  16. const char* what()
  17. {
  18. return what_str;
  19. }
  20. };
  21. class out_of_range : public runtime_error{
  22. public:
  23. out_of_range(const char* what)
  24. : runtime_error{what}
  25. {}
  26. out_of_range()
  27. : runtime_error{}
  28. {
  29. what_str = "out_of_range error has occured";
  30. }
  31. };
  32. class bad_optional : public runtime_error{
  33. public:
  34. bad_optional(const char* what)
  35. : runtime_error{what}
  36. {}
  37. bad_optional()
  38. : runtime_error{}
  39. {
  40. what_str = "bad_optional error has occured";
  41. }
  42. };
  43. template<typename orig, typename target>
  44. class bad_buffer_cast : public runtime_error{
  45. public:
  46. bad_buffer_cast(const char* what)
  47. : runtime_error{what}
  48. {}
  49. bad_buffer_cast()
  50. : runtime_error{}
  51. {
  52. what_str = "bad_buffer_cast error has occured";
  53. }
  54. };
  55. template<typename Expected>
  56. class bad_variant_access : public runtime_error{
  57. public:
  58. bad_variant_access(const char* what)
  59. : runtime_error{what}
  60. {}
  61. bad_variant_access()
  62. : runtime_error{}
  63. {
  64. what_str = "bad_variant_access error has occured";
  65. }
  66. };
  67. class bad_hashmap_access : public runtime_error{
  68. public:
  69. bad_hashmap_access(const char* what)
  70. : runtime_error{what}
  71. {}
  72. bad_hashmap_access()
  73. : runtime_error{}
  74. {
  75. what_str = "bad_hashmap_access error has occured";
  76. }
  77. };
  78. class bad_alloc : public runtime_error{
  79. public:
  80. bad_alloc(const char* what)
  81. : runtime_error{what}
  82. {}
  83. bad_alloc()
  84. : runtime_error{}
  85. {
  86. what_str = "bad_alloc error has occured";
  87. }
  88. };
  89. class bad_functor : public runtime_error{
  90. public:
  91. bad_functor(const char* what)
  92. : runtime_error{what}
  93. {}
  94. bad_functor()
  95. : runtime_error{}
  96. {
  97. what_str = "bad_functor error has occured";
  98. }
  99. };
  100. }