001package jmri;
002
003import java.util.*;
004
005/**
006 * Base for JMRI-specific exceptions. No functionality, just used to confirm
007 * type-safety.
008 *
009 * @author Bob Jacobsen Copyright (C) 2001, 2008, 2010
010 */
011public class JmriException extends Exception {
012
013    private final List<String> errors;
014
015    public JmriException(String s, Throwable t) {
016        super(s, t);
017        errors = null;
018    }
019
020    public JmriException(String s) {
021        super(s);
022        errors = null;
023    }
024
025    public JmriException(Throwable t) {
026        super(t);
027        errors = null;
028    }
029
030    public JmriException() {
031        errors = null;
032    }
033
034    public JmriException(String s, List<String> errors) {
035        super(s);
036        this.errors = Collections.unmodifiableList(new ArrayList<>(errors));
037    }
038
039    public JmriException(String s, List<String> errors, Throwable t) {
040        super(s, t);
041        this.errors = Collections.unmodifiableList(new ArrayList<>(errors));
042    }
043
044    public List<String> getErrors() {
045        return errors;
046    }
047
048    /** {@inheritDoc} */
049    @Override
050    public String getMessage() {
051        if (errors != null) {
052            return super.getMessage() + ": " + String.join(", ", errors);
053        } else {
054            return super.getMessage();
055        }
056    }
057
058    /** {@inheritDoc} */
059    @Override
060    public String getLocalizedMessage() {
061        if (errors != null) {
062            return super.getLocalizedMessage() + ": " + String.join(", ", errors);
063        } else {
064            return super.getLocalizedMessage();
065        }
066    }
067
068}