Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d00666

Browse files
Challenge 9.
Exception hierarchy
1 parent fab73e0 commit 3d00666

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎src/main/java/Challenge_10.java‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.io.Closeable;
2+
import java.io.IOException;
3+
4+
/**
5+
* str.matches(regExp) return tru if str matches the given regular expressions.
6+
*
7+
* RuntimeException extends Exception extends Throwable.
8+
* StackOverflowError extends Error extends Throwable.
9+
*
10+
* in a try with resources block, when an exception is thrown, the resource is closed before any catch block.
11+
*
12+
*/
13+
public class Challenge_10 {
14+
public static void main( String[] args ) {
15+
String soprano = null;
16+
CloseIt closeIt = new CloseIt();
17+
try (closeIt){
18+
System.out.println(soprano.matches(null));
19+
}catch (RuntimeException re){
20+
try (closeIt){
21+
System.out.println("runtime");
22+
throw new StackOverflowError();
23+
}
24+
catch(Exception e){
25+
System.out.println("exception");
26+
}
27+
}
28+
catch (Error error){
29+
System.out.println("error");
30+
}
31+
catch (Throwable throwable){
32+
System.out.println("throwable");
33+
}
34+
}
35+
36+
private static class CloseIt implements Closeable {
37+
@Override
38+
public void close() throws IOException {
39+
System.out.println("close");
40+
}
41+
}
42+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /