1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.mapcss;
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * MapCSS parsing error, with line/column information in error message.
|
---|
6 | */
|
---|
7 | public class MapCSSException extends RuntimeException {
|
---|
8 |
|
---|
9 | /** line number at which the parse error occurred */
|
---|
10 | protected Integer line;
|
---|
11 | /** column number at which the parse error occurred */
|
---|
12 | protected Integer column;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Constructs a new {@code MapCSSException} with an explicit error message.
|
---|
16 | * @param specialMessage error message
|
---|
17 | */
|
---|
18 | public MapCSSException(String specialMessage) {
|
---|
19 | super(specialMessage);
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Constructs a new {@code MapCSSException} with a cause.
|
---|
24 | * @param cause the root cause
|
---|
25 | * @since 11562
|
---|
26 | */
|
---|
27 | public MapCSSException(Throwable cause) {
|
---|
28 | super(cause);
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Sets the column number at which the parse error occurred.
|
---|
33 | * @param column the column number at which the parse error occurred
|
---|
34 | */
|
---|
35 | public void setColumn(int column) {
|
---|
36 | this.column = column;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Sets the line number at which the parse error occurred.
|
---|
41 | * @param line the line number at which the parse error occurred
|
---|
42 | */
|
---|
43 | public void setLine(int line) {
|
---|
44 | this.line = line;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public String getMessage() {
|
---|
49 | if (line == null || column == null)
|
---|
50 | return super.getMessage();
|
---|
51 | return String.format("Error at line %s, column %s: %s", line, column, super.getMessage());
|
---|
52 | }
|
---|
53 | }
|
---|