View Javadoc

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.4 2005/06/09 19:51:59 blackdrag Exp $
16   */
17  
18  public class ExceptionMessage extends Message
19  {
20      protected boolean verbose = true;
21  
22      private Exception cause = null;   // The exception source of the message, if any
23      ProcessingUnit owner = null;
24  
25      public ExceptionMessage( Exception cause, boolean v, ProcessingUnit owner )
26      {
27          this.verbose = v;
28          this.cause = cause;
29          this.owner = owner;
30      }
31      
32      
33     
34     /***
35      *  Returns the underlying Exception.
36      */
37  
38      public Exception getCause()
39      {
40          return this.cause;
41      }
42      
43  
44  
45     /***
46      *  Writes out a nicely formatted summary of the exception. 
47      */
48      
49      public void write( PrintWriter output, Janitor janitor )
50      {
51          String description = "General error during " + owner.getPhaseDescription() + ": "; 
52          
53          String message = cause.getMessage();
54          if( message != null )
55          {
56              output.println( description + message );
57          }
58          else
59          {
60              output.println( description + cause );
61          }
62          output.println("");
63  
64          if (verbose) {
65              cause.printStackTrace(output);
66          }
67      }
68      
69  }
70  
71  
72