protected void handleException(final Exception e) throws BuildException { assert e != null; Writer writer = new StringBuilderWriter(); new ErrorReporter(e, false).write(new PrintWriter(writer)); String message = writer.toString(); if (failOnError) { throw new BuildException(message, e, getLocation()); } else { log.error(message); } }
/** * Writes the error to the specified <code>PrintStream</code>. */ public void write( PrintStream stream ) { this.output = stream; dispatch( base, false ); stream.flush(); }
/** * For Exception. */ protected void report( Exception e, boolean child ) { println( e.getMessage() ); stacktrace( e, false ); }
/** * Displays an exception's stack trace, if <code>debug</code> or * <code>always</code>. */ protected void stacktrace( Throwable e, boolean always ) { if( debug || always ) { println( ">>> stacktrace:" ); if( output instanceof PrintStream ) { e.printStackTrace( (PrintStream)output ); } else { e.printStackTrace( (PrintWriter)output ); } } }
/** * Runs the report once all initialization is complete. */ protected void dispatch( Throwable object, boolean child ) { if( object instanceof CompilationFailedException ) { report( (CompilationFailedException)object, child ); } else if( object instanceof GroovyExceptionInterface ) { report( (GroovyExceptionInterface)object, child ); } else if( object instanceof GroovyRuntimeException ) { report( (GroovyRuntimeException)object, child ); } else if( object instanceof Exception ) { report( (Exception)object, child ); } else { report( object, child ); } }
/** * Displays an exception's stack trace, if <code>debug</code> or * <code>always</code>. */ protected void stacktrace( Throwable e, boolean always ) { if( debug || always ) { println( ">>> stacktrace:" ); if( output instanceof PrintStream ) { e.printStackTrace( (PrintStream)output ); } else { e.printStackTrace( (PrintWriter)output ); } } }
/** * Runs the report once all initialization is complete. */ protected void dispatch( Throwable object, boolean child ) { if( object instanceof CompilationFailedException ) { report( (CompilationFailedException)object, child ); } else if( object instanceof GroovyExceptionInterface ) { report( (GroovyExceptionInterface)object, child ); } else if( object instanceof GroovyRuntimeException ) { report( (GroovyRuntimeException)object, child ); } else if( object instanceof Exception ) { report( (Exception)object, child ); } else { report( object, child ); } }
/** * Primary entry point for compiling from the command line * (using the groovyc script). * <p> * If calling inside a process and you don't want the JVM to exit on an * error call commandLineCompile(String[]), which this method simply wraps * * @param args command line arguments * @param lookupUnnamedFiles do a lookup for .groovy files not part of * the given list of files to compile */ public static void commandLineCompileWithErrorHandling(String[] args, boolean lookupUnnamedFiles) { try { commandLineCompile(args, lookupUnnamedFiles); } catch (Throwable e) { new ErrorReporter(e, displayStackTraceOnError).write(System.err); System.exit(1); } }
/** * For everything else. */ protected void report( Throwable e, boolean child ) { println( ">>> a serious error occurred: " + e.getMessage() ); stacktrace( e, true ); }
/** * Writes the error to the specified <code>PrintWriter</code>. */ public void write( PrintWriter writer ) { this.output = writer; dispatch( base, false ); writer.flush(); }
/** * Displays an exception's stack trace, if <code>debug</code> or * <code>always</code>. */ protected void stacktrace( Throwable e, boolean always ) { if( debug || always ) { println( ">>> stacktrace:" ); if( output instanceof PrintStream ) { e.printStackTrace( (PrintStream)output ); } else { e.printStackTrace( (PrintWriter)output ); } } }
/** * Runs the report once all initialization is complete. */ protected void dispatch( Throwable object, boolean child ) { if( object instanceof CompilationFailedException ) { report( (CompilationFailedException)object, child ); } else if( object instanceof GroovyExceptionInterface ) { report( (GroovyExceptionInterface)object, child ); } else if( object instanceof GroovyRuntimeException ) { report( (GroovyRuntimeException)object, child ); } else if( object instanceof Exception ) { report( (Exception)object, child ); } else { report( object, child ); } }
new ErrorReporter(t, false).write(new PrintWriter(writer)); String message = writer.toString();
/** * For GroovyException. */ protected void report( GroovyExceptionInterface e, boolean child ) { println( ((Exception)e).getMessage() ); stacktrace( (Exception)e, false ); }
/** * Writes the error to the specified <code>PrintWriter</code>. */ public void write( PrintWriter writer ) { this.output = writer; dispatch( base, false ); writer.flush(); }
/** * Displays an exception's stack trace, if <code>debug</code> or * <code>always</code>. */ protected void stacktrace( Throwable e, boolean always ) { if( debug || always ) { println( ">>> stacktrace:" ); if( output instanceof PrintStream ) { e.printStackTrace( (PrintStream)output ); } else { e.printStackTrace( (PrintWriter)output ); } } }
/** * Runs the report once all initialization is complete. */ protected void dispatch( Throwable object, boolean child ) { if( object instanceof CompilationFailedException ) { report( (CompilationFailedException)object, child ); } else if( object instanceof GroovyExceptionInterface ) { report( (GroovyExceptionInterface)object, child ); } else if( object instanceof GroovyRuntimeException ) { report( (GroovyRuntimeException)object, child ); } else if( object instanceof Exception ) { report( (Exception)object, child ); } else { report( object, child ); } }
/** * Reports the last parsing error to the user. */ private void report() { err.println("Discarding invalid text:"); // TODO: i18n new ErrorReporter(error, false).write(err); }
/** * For CompilationFailedException. */ protected void report( CompilationFailedException e, boolean child ) { println( e.toString() ); stacktrace( e, false ); }
/** * Writes the error to the specified <code>PrintWriter</code>. */ public void write( PrintWriter writer ) { this.output = writer; dispatch( base, false ); writer.flush(); }