FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/exceptions/ExtraFeatures.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
/
ExtraFeatures.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (69 loc) · 1.99 KB
Breadcrumbs
OnJava8-Examples
/
exceptions
/
ExtraFeatures.java
Copy path
File metadata and controls
71 lines (69 loc) · 1.99 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// exceptions/ExtraFeatures.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.
// Further embellishment of exception classes
class
MyException2
extends
Exception
{
private
int
x
;
MyException2
() {}
MyException2
(
String
msg
) {
super
(
msg
); }
MyException2
(
String
msg
,
int
x
) {
super
(
msg
);
this
.
x
=
x
;
}
public
int
val
() {
return
x
; }
@
Override
public
String
getMessage
() {
return
"Detail Message: "
+
x
+
" "
+
super
.
getMessage
();
}
}
public
class
ExtraFeatures
{
public
static
void
f
()
throws
MyException2
{
System
.
out
.
println
(
"Throwing MyException2 from f()"
);
throw
new
MyException2
();
}
public
static
void
g
()
throws
MyException2
{
System
.
out
.
println
(
"Throwing MyException2 from g()"
);
throw
new
MyException2
(
"Originated in g()"
);
}
public
static
void
h
()
throws
MyException2
{
System
.
out
.
println
(
"Throwing MyException2 from h()"
);
throw
new
MyException2
(
"Originated in h()"
,
47
);
}
public
static
void
main
(
String
[]
args
) {
try
{
f
();
}
catch
(
MyException2
e
) {
e
.
printStackTrace
(
System
.
out
);
}
try
{
g
();
}
catch
(
MyException2
e
) {
e
.
printStackTrace
(
System
.
out
);
}
try
{
h
();
}
catch
(
MyException2
e
) {
e
.
printStackTrace
(
System
.
out
);
System
.
out
.
println
(
"e.val() = "
+
e
.
val
());
}
}
}
/* Output:
Throwing MyException2 from f()
MyException2: Detail Message: 0 null
at ExtraFeatures.f(ExtraFeatures.java:23)
at ExtraFeatures.main(ExtraFeatures.java:37)
Throwing MyException2 from g()
MyException2: Detail Message: 0 Originated in g()
at ExtraFeatures.g(ExtraFeatures.java:28)
at ExtraFeatures.main(ExtraFeatures.java:42)
Throwing MyException2 from h()
MyException2: Detail Message: 47 Originated in h()
at ExtraFeatures.h(ExtraFeatures.java:33)
at ExtraFeatures.main(ExtraFeatures.java:47)
e.val() = 47
*/
Back
|
FazBrowse Home
|
New Git URL