config_exceptions.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //Exceptions that the library might throw in case of
  2. //error conditions as noted.
  3. #ifndef CONFIG_EXCEPTIONS_HPP
  4. #define CONFIG_EXCEPTIONS_HPP
  5. // Config Class
  6. // Author: Charles Gruenwald III
  7. #include <iostream>
  8. #include <exception>
  9. namespace config
  10. {
  11. //This error gets thrown then the parse is unsuccessful
  12. class parserError: public std::exception
  13. {
  14. public:
  15. parserError(const String & leftover)
  16. :
  17. m_leftover("parser Error: " + leftover)
  18. {
  19. }
  20. virtual ~parserError() throw() {}
  21. virtual const char* what() const throw()
  22. {
  23. return m_leftover.c_str();
  24. }
  25. private:
  26. String m_leftover;
  27. };
  28. //This error gets thrown when a key is not found
  29. class KeyNotFound: public std::exception
  30. {
  31. virtual const char* what() const throw()
  32. {
  33. return "Key not found.";
  34. }
  35. };
  36. //This error gets thrown when a key is not found
  37. class FileNotFound: public std::exception
  38. {
  39. public:
  40. FileNotFound(const String &filename)
  41. {
  42. m_filename = String("File not found: [") + filename + String("]");
  43. }
  44. virtual ~FileNotFound() throw() {}
  45. virtual const char* what() const throw()
  46. {
  47. return m_filename.c_str();
  48. }
  49. private:
  50. String m_filename;
  51. };
  52. //This error gets thrown then the parse is unsuccessful
  53. class SaveError: public std::exception
  54. {
  55. public:
  56. SaveError(const String & error_str)
  57. :
  58. m_error("Save Error: " + error_str)
  59. {
  60. }
  61. virtual ~SaveError() throw() {}
  62. virtual const char* what() const throw()
  63. {
  64. return m_error.c_str();
  65. }
  66. private:
  67. String m_error;
  68. };
  69. }
  70. #endif