001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint.mapcss;
003
004/**
005 * MapCSS parsing error, with line/columnn information in error message.
006 */
007public class MapCSSException extends RuntimeException {
008
009    /** line number at which the parse error occured */
010    protected Integer line;
011    /** column number at which the parse error occured */
012    protected Integer column;
013
014    /**
015     * Constructs a new {@code MapCSSException} with an explicit error message.
016     * @param specialmessage error message
017     */
018    public MapCSSException(String specialmessage) {
019        super(specialmessage);
020    }
021
022    /**
023     * Constructs a new {@code MapCSSException} with a cause.
024     * @param cause the root cause
025     * @since 11562
026     */
027    public MapCSSException(Throwable cause) {
028        super(cause);
029    }
030
031    /**
032     * Sets the column number at which the parse error occured.
033     * @param column the column number at which the parse error occured
034     */
035    public void setColumn(int column) {
036        this.column = column;
037    }
038
039    /**
040     * Sets the line number at which the parse error occured.
041     * @param line the line number at which the parse error occured
042     */
043    public void setLine(int line) {
044        this.line = line;
045    }
046
047    @Override
048    public String getMessage() {
049        if (line == null || column == null)
050            return super.getMessage();
051        return String.format("Error at line %s, column %s: %s", line, column, super.getMessage());
052    }
053}