1 package org.codehaus.groovy.control.messages;
2
3 import java.io.PrintWriter;
4
5 import org.codehaus.groovy.control.Janitor;
6 import org.codehaus.groovy.control.ProcessingUnit;
7
8
9
10 /***
11 * A class for error messages produced by the parser system.
12 *
13 * @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
14 *
15 * @version $Id: ExceptionMessage.java,v 1.3 2005/01/26 19:09:05 jstrachan Exp $
16 */
17
18 public class ExceptionMessage extends Message
19 {
20 protected static final boolean verbose = true;
21
22 private Exception cause = null;
23
24
25 public ExceptionMessage( Exception cause )
26 {
27 this.cause = cause;
28 }
29
30
31
32 /***
33 * Returns the underlying Exception.
34 */
35
36 public Exception getCause()
37 {
38 return this.cause;
39 }
40
41
42
43 /***
44 * Writes out a nicely formatted summary of the exception.
45 */
46
47 public void write( PrintWriter output, ProcessingUnit context, Janitor janitor )
48 {
49 String description = "General error during " + context.getPhaseDescription() + ": ";
50
51 String message = cause.getMessage();
52 if( message != null )
53 {
54 output.println( description + message );
55 }
56 else
57 {
58 output.println( description + cause );
59 }
60 output.println("");
61
62 if (verbose) {
63 cause.printStackTrace(output);
64 }
65 }
66
67
68 }
69
70
71