SAXException.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // SAXException.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // SAX exception classes.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef SAX_SAXException_INCLUDED
  16. #define SAX_SAXException_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLException.h"
  19. #include "Poco/XML/XMLString.h"
  20. namespace Poco {
  21. namespace XML {
  22. POCO_DECLARE_EXCEPTION(XML_API, SAXException, XMLException)
  23. /// The base class for all SAX-related exceptions like SAXParseException,
  24. /// SAXNotRecognizedException or SAXNotSupportedException.
  25. ///
  26. /// This class can contain basic error or warning information from either the XML parser
  27. /// or the application: a parser writer or application writer can subclass it to provide
  28. /// additional functionality. SAX handlers may throw this exception or any exception subclassed
  29. /// from it.
  30. ///
  31. /// If the application needs to pass through other types of exceptions, it must wrap those exceptions
  32. /// in a SAXException or an exception derived from a SAXException.
  33. ///
  34. /// If the parser or application needs to include information about a specific location in an XML
  35. /// document, it should use the SAXParseException subclass.
  36. POCO_DECLARE_EXCEPTION(XML_API, SAXNotRecognizedException, SAXException)
  37. /// Exception class for an unrecognized identifier.
  38. ///
  39. /// An XMLReader will throw this exception when it finds an unrecognized feature or property
  40. /// identifier; SAX applications and extensions may use this class for other, similar purposes.
  41. POCO_DECLARE_EXCEPTION(XML_API, SAXNotSupportedException, SAXException)
  42. /// Exception class for an unsupported operation.
  43. ///
  44. /// An XMLReader will throw this exception when it recognizes a feature or property identifier,
  45. /// but cannot perform the requested operation (setting a state or value). Other SAX2 applications
  46. /// and extensions may use this class for similar purposes.
  47. class Locator;
  48. class XML_API SAXParseException: public SAXException
  49. /// Encapsulate an XML parse error or warning.
  50. ///
  51. /// This exception may include information for locating the error in the original XML document,
  52. /// as if it came from a Locator object. Note that although the application will receive a
  53. /// SAXParseException as the argument to the handlers in the ErrorHandler interface, the application
  54. /// is not actually required to throw the exception; instead, it can simply read the information in it
  55. /// and take a different action.
  56. ///
  57. /// Since this exception is a subclass of SAXException, it inherits the ability to wrap another exception.
  58. {
  59. public:
  60. SAXParseException(const std::string& msg, const Locator& loc);
  61. /// Create a new SAXParseException from a message and a Locator.
  62. SAXParseException(const std::string& msg, const Locator& loc, const Poco::Exception& exc);
  63. /// Wrap an existing exception in a SAXParseException.
  64. SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber);
  65. /// Create a new SAXParseException with an embedded exception.
  66. ///
  67. /// This constructor is most useful for parser writers.
  68. /// All parameters except the message are as if they were provided by a Locator.
  69. /// For example, if the system identifier is a URL (including relative filename),
  70. /// the caller must resolve it fully before creating the exception.
  71. SAXParseException(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber, const Poco::Exception& exc);
  72. /// Create a new SAXParseException.
  73. ///
  74. /// This constructor is most useful for parser writers.
  75. /// All parameters except the message are as if they were provided by a Locator.
  76. /// For example, if the system identifier is a URL (including relative filename),
  77. /// the caller must resolve it fully before creating the exception.
  78. SAXParseException(const SAXParseException& exc);
  79. /// Creates a new SAXParseException from another one.
  80. ~SAXParseException() noexcept;
  81. /// Destroy the exception.
  82. SAXParseException& operator = (const SAXParseException& exc);
  83. /// Assignment operator.
  84. const char* name() const noexcept;
  85. /// Returns a static string describing the exception.
  86. const char* className() const noexcept;
  87. /// Returns the name of the exception class.
  88. Poco::Exception* clone() const;
  89. /// Creates an exact copy of the exception.
  90. void rethrow() const;
  91. /// (Re)Throws the exception.
  92. const XMLString& getPublicId() const;
  93. /// Get the public identifier of the entity where the exception occurred.
  94. const XMLString& getSystemId() const;
  95. /// Get the system identifier of the entity where the exception occurred.
  96. int getLineNumber() const;
  97. /// The line number of the end of the text where the exception occurred.
  98. /// The first line is line 1.
  99. int getColumnNumber() const;
  100. /// The column number of the end of the text where the exception occurred.
  101. /// The first column in a line is position 1.
  102. protected:
  103. static std::string buildMessage(const std::string& msg, const XMLString& publicId, const XMLString& systemId, int lineNumber, int columnNumber);
  104. private:
  105. SAXParseException();
  106. XMLString _publicId;
  107. XMLString _systemId;
  108. int _lineNumber;
  109. int _columnNumber;
  110. };
  111. //
  112. // inlines
  113. //
  114. inline const XMLString& SAXParseException::getPublicId() const
  115. {
  116. return _publicId;
  117. }
  118. inline const XMLString& SAXParseException::getSystemId() const
  119. {
  120. return _systemId;
  121. }
  122. inline int SAXParseException::getLineNumber() const
  123. {
  124. return _lineNumber;
  125. }
  126. inline int SAXParseException::getColumnNumber() const
  127. {
  128. return _columnNumber;
  129. }
  130. } } // namespace Poco::XML
  131. #endif // SAX_SAXException_INCLUDED