Skip to content

Instantly share code, notes, and snippets.

@sungjk
Created June 22, 2018 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sungjk/ca37befc557e5a6680e7fa0a888806f2 to your computer and use it in GitHub Desktop.
Save sungjk/ca37befc557e5a6680e7fa0a888806f2 to your computer and use it in GitHub Desktop.
try-catch-finally on Java
public static String lem() {
System.out.println("lem");
return "return from lem";
}
public static String foo() {
int x = 0;
int y = 5;
try {
System.out.println("start try");
int b = y / x;
System.out.println("end try");
return "returned from try";
}
catch (Exception ex) {
System.out.println("catch");
return lem() + " | returned from catch";
}
finally {
System.out.println("finally");
}
}
public static void bar() {
System.out.println("start bar");
String v = foo();
System.out.println(v);
System.out.println("end bar");
}
public static void main(String[] args) {
bar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment