File tree Expand file tree Collapse file tree
main/java/com/baeldung/exceptionhandling
test/java/com/baeldung/exceptionhandling
maven/src/test/java/testfail Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ public static List<Player> getPlayers() throws IOException {
2525 }
2626
2727 public List <Player > loadAllPlayers (String playersFile ) throws IOException {
28- throw new IOException ();
28+ try {
29+ throw new IOException ();
30+ } catch (IOException ex ) {
31+ throw new IllegalStateException ();
32+ }
2933 }
3034
3135 public int getPlayerScoreThrows (String playerFile ) throws FileNotFoundException {
@@ -160,7 +164,13 @@ public List<Player> loadAllPlayers(String playersFile) { //can't add "throws My
160164 }
161165
162166 public void throwAsGotoAntiPattern () throws MyException {
163- throw new MyException ();
167+ try {
168+ // bunch of code
169+ throw new MyException ();
170+ // second bunch of code
171+ } catch ( MyException e ) {
172+ // third bunch of code
173+ }
164174 }
165175
166176 public int getPlayerScoreSwallowingExceptionAntiPattern (String playerFile ) {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public void getPlayers() {
2121 @ Test
2222 public void loadAllPlayers () {
2323 assertThatThrownBy (() -> exceptions .loadAllPlayers ("" ))
24- .isInstanceOf (IOException .class );
24+ .isInstanceOf (IllegalStateException .class );
2525 }
2626
2727 @ Test
@@ -72,12 +72,6 @@ public void loadAllPlayersThrowable() {
7272 .isInstanceOf (NullPointerException .class );
7373 }
7474
75- @ Test
76- public void throwAsGotoAntiPattern () {
77- assertThatThrownBy (() -> exceptions .throwAsGotoAntiPattern ())
78- .isInstanceOf (MyException .class );
79- }
80-
8175 @ Test
8276 public void getPlayerScoreSwallowingExceptionAntiPatternAlternative2 () {
8377 assertThatThrownBy (() -> exceptions .getPlayerScoreSwallowingExceptionAntiPatternAlternative2 ("" ))
Original file line number Diff line number Diff line change 11package testfail ;
22
33import org .junit .Test ;
4+ import org .junit .Ignore ;
45
56import static org .junit .Assert .assertNotNull ;
67
78public class TestFail {
9+
10+ @ Ignore //ignored so the entire tutorials build passes
811 @ Test
912 public void whenMessageAssigned_thenItIsNotNull () {
1013 String message = "hello there" ;
You can’t perform that action at this time.
0 commit comments