hl_exception.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * hashlib++ - a simple hash library for C++
  3. *
  4. * Copyright (c) 2007-2010 Benjamin Grüdelbach
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1) Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * 2) Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  21. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. //----------------------------------------------------------------------
  29. /**
  30. * @file hl_exception.h
  31. * @brief This file contains the hashlib++ exception class
  32. * @date Sa 24 Nov 2007
  33. */
  34. //----------------------------------------------------------------------
  35. //include protection
  36. #ifndef HL_EXCEPTION_H
  37. #define HL_EXCEPTION_H
  38. //----------------------------------------------------------------------
  39. //STL
  40. #include <string>
  41. //----------------------------------------------------------------------
  42. /**
  43. * definition of hashlib++ errornumbers
  44. */
  45. typedef enum hlerrors
  46. {
  47. HL_NO_ERROR = 0,
  48. HL_FILE_READ_ERROR,
  49. HL_VERIFY_TEST_FAILED,
  50. HL_UNKNOWN_SEE_MSG,
  51. HL_UNKNOWN_HASH_TYPE
  52. } hlerror;
  53. //----------------------------------------------------------------------
  54. /**
  55. * @brief This class represents a exception within the hashlib++
  56. * project
  57. */
  58. class hlException
  59. {
  60. private:
  61. /**
  62. * Error Number
  63. */
  64. hlerror iError;
  65. /**
  66. * Error message as string
  67. */
  68. std::string strMessge;
  69. public:
  70. /**
  71. * @brief constructor
  72. * @param er Error number
  73. * @param m Error message
  74. */
  75. hlException(hlerror er, std::string m)
  76. {
  77. this->iError = er;
  78. this->strMessge = m;
  79. }
  80. /**
  81. * @brief constructor
  82. * @param m Error Message
  83. */
  84. hlException(std::string m)
  85. {
  86. this->iError = HL_UNKNOWN_SEE_MSG;
  87. this->strMessge = m;
  88. }
  89. /**
  90. * @brief returns the error message
  91. * @return the error message
  92. */
  93. std::string error_message(void)
  94. {
  95. return strMessge;
  96. }
  97. /**
  98. * @brief returns the error number
  99. * @return the error number
  100. */
  101. hlerror error_number(void)
  102. {
  103. return iError;
  104. }
  105. };
  106. //----------------------------------------------------------------------
  107. //end of include protection
  108. #endif
  109. //----------------------------------------------------------------------
  110. //EOF