summaryrefslogtreecommitdiff
path: root/src/main/java/bjc/rgens/parser/GrammarException.java
blob: 271f7179f68b2f576b539965d5edc696e95c471d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package bjc.rgens.parser;

/**
 * The exception thrown when something goes wrong while parsing a
 * grammar.
 *
 * @author student
 */
public class GrammarException extends RuntimeException {
	/* Serialization ID. */
	private static final long serialVersionUID = -7287427479316953668L;

	private String rootMessage;

	/**
	 * Create a new grammar exception with the specified message.
	 *
	 * @param msg
	 * 	The message for this exception.
	 */
	public GrammarException(String msg) {
		super(msg);
	}

	/**
	 * Create a new grammar exception with the specified message and
	 * cause.
	 *
	 * @param msg
	 * 	The message for this exception.
	 *
	 * @param cause
	 * 	The cause of this exception.
	 */
	public GrammarException(String msg, Exception cause) {
		super(msg, cause);
	}

	/**
	 * Create a new grammar exception with the specified message.
	 *
	 * @param msg
	 * 	The message for this exception.
	 */
	public GrammarException(String msg, String rootMsg) {
		super(msg);

		this.rootMessage = rootMsg;
	}

	/**
	 * Create a new grammar exception with the specified message and
	 * cause.
	 *
	 * @param msg
	 * 	The message for this exception.
	 *
	 * @param cause
	 * 	The cause of this exception.
	 */
	public GrammarException(String msg, Exception cause, String rootMsg) {
		super(msg, cause);

		this.rootMessage = rootMsg;
	}

	/**
	 * Get the root cause of this exception.
	 *
	 * @return The root cause of this exception.
	 */
	public String getRootMessage() {
		return rootMessage == null? getMessage() : rootMessage;
	}
}