Skip to content

Commit

Permalink
Add finally exit method example
Browse files Browse the repository at this point in the history
  • Loading branch information
Rollczi authored and northpl93 committed Jan 27, 2024
1 parent dfcc510 commit 19ed014
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/FinallyExitMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class FinallyExitMethod
{

@Test
public void test()
{
assertTrue(finallyExitMethod() == 2);
}

private static int finallyExitMethod()
{
try
{
throw new Exception();
}
catch (final Exception exception)
{
System.out.println("catch");
return printAndGetNumber(1);
}
finally
{
System.out.println("finally");
return printAndGetNumber(2);
}
}

private static int printAndGetNumber(int number)
{
System.out.println("number: " + number);
return number;
}

}

0 comments on commit 19ed014

Please sign in to comment.