1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Encapsulates an XML parse error or warning.
12 module sax
::sax_parse_exception
16 # Encapsulates an XML parse error or warning.
18 # This exception may include information for locating the error
19 # in the original XML document, as if it came from a `Locator`
20 # object. Note that although the application
21 # will receive a `SAXParseException` as the argument to the handlers
22 # in the `ErrorHandler` interface,
23 # the application is not actually required to throw the exception;
24 # instead, it can simply read the information in it and take a
27 # Note: The original documentation comes, in part,
28 # from [SAX 2.0](http://www.saxproject.org).
30 # SEE: `sax::SAXLocator`
32 # SEE: `sax::ErrorHandler`
33 class SAXParseException
36 # The public identifer of the entity that generated
37 # the error or warning.
38 var public_id
: nullable String = null
40 # The system identifer of the entity that generated
41 # the error or warning.
43 # If its an URL, it must be fully resolved.
44 var system_id
: nullable String = null
46 # The line number of the end of the text that
47 # caused the error or warning, or -1.
50 # The column number of the end of the text that
51 # caused the error or warning, or -1.
52 var column_number
= -1
54 # Create a new SAXParseException from a message and a Locator.
56 # This constructor is especially useful when an application is
57 # creating its own exception from within a `ContentHandler` callback.
61 # * `message`: error or warning message.
62 # * `locator`: locator object for the error or warning.
63 init with_locator
(message
: String, locator
: SAXLocator) do
65 public_id
= locator
.public_id
66 system_id
= locator
.system_id
67 line_number
= locator
.line_number
68 column_number
= locator
.column_number
71 # Create a new SAXParseException.
73 # This constructor is most useful for parser writers.
75 # All parameters except the message are as if they were provided by a
76 # `Locator`. For example, if the system identifier is a URL (including
77 # relative filename), the caller must resolve it fully before creating the
82 # * `message`: error or warning message.
83 # * `public_id`: public identifer of the entity that generated
84 # the error or warning.
85 # * `system_id`: system identifer of the entity that generated
86 # the error or warning.
87 # * `line_number`: line number of the end of the text that
88 # caused the error or warning.
89 # * `column_number`: column number of the end of the text that
90 # caused the error or warning.
91 init with_info
(message
: String, public_id
: nullable String,
92 system_id
: nullable String, line_number
: Int, column_number
: Int) do
94 self.public_id
= public_id
95 self.system_id
= system_id
96 self.line_number
= line_number
97 self.column_number
= column_number
100 # Generate a complete message from the exception’s attributes.
101 fun full_message
: String do
104 if public_id
!= null then
105 location
= "PUBLIC \"{public_id.as(not null)}\
""
107 if system_id
!= null then
108 if location
!= "" then
111 location
+= "SYSTEM \"{system_id.as(not null)}\
""
113 if line_number
>= 0 or column_number
>= 0 then
114 if location
!= "" then
117 location
+= "{line_number};{column_number}"
119 if location
== "" then
122 return "[{location}] {message}"
127 return "sax::SAXParseException: {full_message}"
130 # Display `full_message` with a stack trace, then abort.
132 assert sax_parse
: false else
133 sys
.stderr
.write
"{full_message}\n"