source: josm/trunk/src/org/openstreetmap/josm/io/XmlStreamParsingException.java@ 11114

Last change on this file since 11114 was 10235, checked in by Don-vip, 8 years ago

sonar - squid:S00112 - Generic exceptions should never be thrown

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import javax.xml.stream.Location;
7import javax.xml.stream.XMLStreamException;
8
9/**
10 * Exception for unexpected processing errors during XML stream parsing.
11 * It uses proper JOSM i18n system to translate error message, including file location.
12 * @since 10235
13 */
14public class XmlStreamParsingException extends XMLStreamException {
15
16 /**
17 * Constructs a new {@code XmlStreamParsingException}.
18 * @param msg error message
19 * @param location file location
20 */
21 public XmlStreamParsingException(String msg, Location location) {
22 super(msg); /* cannot use super(msg, location) because it messes with the message preventing localization */
23 this.location = location;
24 }
25
26 /**
27 * Constructs a new {@code XmlStreamParsingException}.
28 * @param msg error message
29 * @param location file location
30 * @param th Throwable cause
31 */
32 public XmlStreamParsingException(String msg, Location location, Throwable th) {
33 super(msg, th);
34 this.location = location;
35 }
36
37 @Override
38 public String getMessage() {
39 String msg = super.getMessage();
40 if (msg == null) {
41 msg = getClass().getName();
42 }
43 if (getLocation() == null)
44 return msg;
45 msg += ' ' + tr("(at line {0}, column {1})", getLocation().getLineNumber(), getLocation().getColumnNumber());
46 int offset = getLocation().getCharacterOffset();
47 if (offset > -1) {
48 msg += ". "+ tr("{0} bytes have been read", offset);
49 }
50 return msg;
51 }
52}
Note: See TracBrowser for help on using the repository browser.