FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/exceptions/RethrowNew.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
exceptions
/
RethrowNew.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (44 loc) · 1.34 KB
Breadcrumbs
OnJava8-Examples
/
exceptions
/
RethrowNew.java
Copy path
File metadata and controls
47 lines (44 loc) · 1.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// exceptions/RethrowNew.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Rethrow a different object from the one you caught
class
OneException
extends
Exception
{
OneException
(
String
s
) {
super
(
s
); }
}
class
TwoException
extends
Exception
{
TwoException
(
String
s
) {
super
(
s
); }
}
public
class
RethrowNew
{
public
static
void
f
()
throws
OneException
{
System
.
out
.
println
(
"originating the exception in f()"
);
throw
new
OneException
(
"thrown from f()"
);
}
public
static
void
main
(
String
[]
args
) {
try
{
try
{
f
();
}
catch
(
OneException
e
) {
System
.
out
.
println
(
"Caught in inner try, e.printStackTrace()"
);
e
.
printStackTrace
(
System
.
out
);
throw
new
TwoException
(
"from inner try"
);
}
}
catch
(
TwoException
e
) {
System
.
out
.
println
(
"Caught in outer try, e.printStackTrace()"
);
e
.
printStackTrace
(
System
.
out
);
}
}
}
/* Output:
originating the exception in f()
Caught in inner try, e.printStackTrace()
OneException: thrown from f()
at RethrowNew.f(RethrowNew.java:16)
at RethrowNew.main(RethrowNew.java:21)
Caught in outer try, e.printStackTrace()
TwoException: from inner try
at RethrowNew.main(RethrowNew.java:26)
*/
Back
|
FazBrowse Home
|
New Git URL