exception.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // exception.h
  3. // dice-roll
  4. //
  5. // Created by Sam Jaffe on 12/1/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <stdexcept>
  10. namespace dice {
  11. class unexpected_token : public std::runtime_error {
  12. public:
  13. /**
  14. * @brief An error for failure to parse a string into a dice::dice object
  15. * @param reason The specific reason that this error occured
  16. * @param position The index into the string that the error was located at,
  17. * or -1(EOF) if the error was a 'we ran out of buffer' type.
  18. */
  19. unexpected_token(std::string const & reason, long long position);
  20. /**
  21. * @brief Create a string matching the regex '~*^', that points to the error
  22. * covered by this exception class.
  23. * @param backup_length If {@see unexpected_token::position} == -1, use
  24. * this value instead as N.
  25. * @return A string of N '~' and one '^', pointing to the character in the
  26. * parse string that the error occured at.
  27. * "<END>" if position and backup_length are both -1
  28. */
  29. std::string pointer(long long backup_length = -1) const;
  30. private:
  31. long long position;
  32. };
  33. }