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 package org.codehaus.groovy;
46
47 /***
48 * This class represents an error that is thrown when a bug is
49 * recognized inside the runtime. Basically it is thrown when
50 * a constraint is not fullfilled that should be fullfiled.
51 *
52 * @author Jochen Theodorou
53 */
54 public class GroovyBugError extends AssertionError {
55
56
57 private String message;
58
59 private Exception exception;
60
61 /***
62 * constructs a bug error using the given text
63 * @param text the error message text
64 */
65 public GroovyBugError( String message ) {
66 this.message = message;
67 }
68
69 /***
70 * Constructs a bug error using the given exception
71 * @param exception cause of this error
72 */
73 public GroovyBugError( Exception exception ) {
74 this.exception = exception;
75 }
76
77 /***
78 * Constructs a bug error using the given exception and
79 * a text with additional information about the cause
80 * @param msg additional information about this error
81 * @param exception cause of this error
82 */
83 public GroovyBugError( String msg, Exception exception )
84 {
85 this.exception = exception;
86 this.message = msg;
87 }
88
89 /***
90 * Returns a String representation of this class by calling <code>getMessage()</code>.
91 * @see #getMessage()
92 */
93 public String toString() {
94 return getMessage();
95 }
96
97 /***
98 * Returns the detail message string of this error. The message
99 * will consist of the bug text prefixed by "BUG! " if there this
100 * isntance was created using a message. If this error was
101 * constructed without using a bug text the message of the cause
102 * is used prefixed by "BUG! UNCAUGHT EXCEPTION: "
103 *
104 * @return the detail message string of this error.
105 */
106 public String getMessage() {
107 if( message != null )
108 {
109 return "BUG! "+message;
110 }
111 else
112 {
113 return "BUG! UNCAUGHT EXCEPTION: " + exception.getMessage();
114 }
115 }
116
117 public Throwable getCause() {
118 return this.exception;
119 }
120
121 /***
122 * Returns the bug text to describe this error
123 */
124 public String getBugText(){
125 if( message != null ){
126 return message;
127 } else {
128 return exception.getMessage();
129 }
130 }
131
132 /***
133 * Sets the bug text to describe this error
134 */
135 public void setBugText(String msg) {
136 this.message = msg;
137 }
138 }