diff options
Diffstat (limited to 'test/008-exceptions/src/Main.java')
| -rw-r--r-- | test/008-exceptions/src/Main.java | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/test/008-exceptions/src/Main.java b/test/008-exceptions/src/Main.java index 7f6d0c5956..c0502047d0 100644 --- a/test/008-exceptions/src/Main.java +++ b/test/008-exceptions/src/Main.java @@ -14,20 +14,38 @@ * limitations under the License. */ -// An exception that doesn't have a <init>(String) method. +// An error class. class BadError extends Error { - public BadError() { - super("This is bad by convention"); + public BadError(String s) { + super("This is bad by convention: " + s); } } -// A class that throws BadException during static initialization. +// A class that throws BadError during static initialization. class BadInit { static int dummy; static { System.out.println("Static Init"); if (true) { - throw new BadError(); + throw new BadError("BadInit"); + } + } +} + +// An error that doesn't have a <init>(String) method. +class BadErrorNoStringInit extends Error { + public BadErrorNoStringInit() { + super("This is bad by convention"); + } +} + +// A class that throws BadErrorNoStringInit during static initialization. +class BadInitNoStringInit { + static int dummy; + static { + System.out.println("Static BadInitNoStringInit"); + if (true) { + throw new BadErrorNoStringInit(); } } } @@ -48,6 +66,7 @@ public class Main { public static void main (String args[]) { exceptions_007(); exceptionsRethrowClassInitFailure(); + exceptionsRethrowClassInitFailureNoStringInit(); } private static void catchAndRethrow() { @@ -86,4 +105,26 @@ public class Main { error.printStackTrace(); } } + + private static void exceptionsRethrowClassInitFailureNoStringInit() { + try { + try { + BadInitNoStringInit.dummy = 1; + throw new IllegalStateException("Should not reach here."); + } catch (BadErrorNoStringInit e) { + System.out.println(e); + } + + // Check if it works a second time. + + try { + BadInitNoStringInit.dummy = 1; + throw new IllegalStateException("Should not reach here."); + } catch (BadErrorNoStringInit e) { + System.out.println(e); + } + } catch (Exception error) { + error.printStackTrace(); + } + } } |