exception.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef QTJSONSERIALIZER_EXCEPTION_H
  2. #define QTJSONSERIALIZER_EXCEPTION_H
  3. #include "qtjsonserializer_global.h"
  4. #include <QtCore/qstring.h>
  5. #include <QtCore/qsharedpointer.h>
  6. #include <QtCore/qstack.h>
  7. #if !defined(QT_NO_EXCEPTIONS) && QT_CONFIG(future)
  8. #include <QtCore/qexception.h>
  9. namespace QtJsonSerializer {
  10. //! The exception base class to use for this module
  11. using ExceptionBase = QException;
  12. }
  13. #else
  14. #include <exception>
  15. namespace QtJsonSerializer {
  16. //! The exception base class to use for this module
  17. using ExceptionBase = std::exception;
  18. }
  19. #endif
  20. namespace QtJsonSerializer {
  21. class ExceptionPrivate;
  22. //! Exception thrown by QJsonSerializer if something goes wrong
  23. class Q_JSONSERIALIZER_EXPORT Exception : public ExceptionBase
  24. {
  25. public:
  26. //! The type of a stack of a property trace (name, type)
  27. using PropertyTrace = QStack<QPair<QByteArray, QByteArray>>;
  28. //! Constructor with error message
  29. Exception(const QByteArray &what);
  30. //! @inherit{std::exception::what}
  31. const char *what() const noexcept final;
  32. //! Returns the error message, without the property trace
  33. QByteArray message() const;
  34. //! Returns the property trace
  35. PropertyTrace propertyTrace() const;
  36. //! @inherit{QException::raise}
  37. virtual void raise() const override;
  38. //! @inherit{QException::clone}
  39. virtual ExceptionBase *clone() const override;
  40. protected:
  41. //! @private
  42. QSharedPointer<ExceptionPrivate> d;
  43. };
  44. //! Exception thrown by the serializers if something goes wrong while serializing
  45. class Q_JSONSERIALIZER_EXPORT SerializationException : public Exception
  46. {
  47. public:
  48. //! Constructor with error message
  49. SerializationException(const QByteArray &what);
  50. void raise() const override;
  51. ExceptionBase *clone() const override;
  52. };
  53. //! Exception thrown by the serializers if something goes wrong while deserializing
  54. class Q_JSONSERIALIZER_EXPORT DeserializationException : public Exception
  55. {
  56. public:
  57. //! Constructor with error message
  58. DeserializationException(const QByteArray &what);
  59. void raise() const override;
  60. ExceptionBase *clone() const override;
  61. };
  62. }
  63. #endif // QTJSONSERIALIZER_EXCEPTION_H