001    package org.codehaus.groovy.control.messages;
002    
003    import java.io.PrintWriter;
004    
005    import org.codehaus.groovy.control.Janitor;
006    import org.codehaus.groovy.control.ProcessingUnit;
007    
008    
009    
010    /**
011     *  A class for error messages produced by the parser system.
012     *
013     *  @author <a href="mailto:cpoirier@dreaming.org">Chris Poirier</a>
014     *
015     *  @version $Id: ExceptionMessage.java 4098 2006-10-10 16:09:48Z blackdrag $
016     */
017    
018    public class ExceptionMessage extends Message
019    {
020        protected boolean verbose = true;
021    
022        private Exception cause = null;   // The exception source of the message, if any
023        ProcessingUnit owner = null;
024    
025        public ExceptionMessage( Exception cause, boolean v, ProcessingUnit owner )
026        {
027            this.verbose = v;
028            this.cause = cause;
029            this.owner = owner;
030        }
031        
032        
033       
034       /**
035        *  Returns the underlying Exception.
036        */
037    
038        public Exception getCause()
039        {
040            return this.cause;
041        }
042        
043    
044    
045       /**
046        *  Writes out a nicely formatted summary of the exception. 
047        */
048        
049        public void write( PrintWriter output, Janitor janitor )
050        {
051            String description = "General error during " + owner.getPhaseDescription() + ": "; 
052            
053            String message = cause.getMessage();
054            if( message != null )
055            {
056                output.println( description + message );
057            }
058            else
059            {
060                output.println( description + cause );
061            }
062            output.println();
063    
064            //if (verbose) {
065                cause.printStackTrace(output);
066            //}
067        }
068        
069    }
070    
071    
072