01: /**
02: * InstantJ
03: *
04: * Copyright (C) 2002 Nils Meier
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: */package instantj.compile;
17:
18: import java.io.PrintStream;
19: import java.io.PrintWriter;
20: import java.util.Iterator;
21: import java.util.ArrayList;
22: import java.util.Collection;
23:
24: /**
25: * The exception wrapping the failed attempt to compile source. It
26: * contains a compiler error statement and a collection of errors
27: * encountered.
28: *
29: * @author <A href="mailto:nils@meiers.net">Nils Meier</A>
30: */
31: public class CompilationFailedException extends Exception {
32:
33: /** the wrapped errors */
34: private Collection errors;
35:
36: /**
37: * Constructor
38: * @param msg message explaining what went wrong
39: */
40: public CompilationFailedException(String msg) {
41: this (msg, new ArrayList());
42: }
43:
44: /**
45: * Constructor
46: * @param msg message explaining what went wrong
47: * @param errors a collection of errors (java.lang.String)
48: */
49: public CompilationFailedException(String msg, Collection errors) {
50: super (msg);
51: this .errors = errors;
52: }
53:
54: /**
55: * Returns the errors the compiler ran into
56: * @return the collection of errors (java.lang.String)
57: */
58: public Collection getErrors() {
59: return errors;
60: }
61:
62: /**
63: * Helper to print the compiler's errors to a PrintStream
64: */
65: public void printErrors(PrintStream out) {
66: Iterator errs = errors.iterator();
67: while (errs.hasNext()) {
68: out.println(errs.next());
69: }
70: }
71:
72: /**
73: * Helper to print the compiler's errors to a PrintWriter
74: */
75: public void printErrors(PrintWriter out) {
76: Iterator errs = errors.iterator();
77: while (errs.hasNext()) {
78: out.println(errs.next());
79: }
80: }
81: }
|