Skip to content

Commit ce68ce1

Browse files
binary-joepivovarit
authored andcommitted
BAEL-2516 catching errors in catch blocks (eugenp#7075)
* BAEL-2516 catching errors in catch block * BAEL-2516 catching errors in catch block; classes moved
1 parent 948243e commit ce68ce1

3 files changed

Lines changed: 26 additions & 66 deletions

File tree

core-java-lang/src/main/java/com/baeldung/error/ErrorGenerator.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

core-java-lang/src/test/java/com/baeldung/error/ErrorGeneratorUnitTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.error;
2+
3+
import org.junit.Assert;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
public class ErrorGeneratorUnitTest {
8+
9+
@Test(expected = AssertionError.class)
10+
public void whenError_thenIsNotCaughtByCatchException() {
11+
try {
12+
throw new AssertionError();
13+
} catch (Exception e) {
14+
Assert.fail(); // errors are not caught by catch exception
15+
}
16+
}
17+
18+
@Test
19+
public void whenError_thenIsCaughtByCatchError() {
20+
try {
21+
throw new AssertionError();
22+
} catch (Error e) {
23+
// caught! -> test pass
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)