Created
June 22, 2018 02:04
-
-
Save sungjk/ca37befc557e5a6680e7fa0a888806f2 to your computer and use it in GitHub Desktop.
try-catch-finally on Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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