-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUncheckedIOException.java
More file actions
90 lines (84 loc) · 1.96 KB
/
UncheckedIOException.java
File metadata and controls
90 lines (84 loc) · 1.96 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.io;
import java.util.Objects;
/**
* Wraps an {@link IOException} with an unchecked exception.
*
* @since 1.8
*/
public class UncheckedIOException extends RuntimeException {
private static final long serialVersionUID = -8134305061645241065L;
/**
* Constructs an instance of this class.
*
* @param message
* the detail message, can be null
* @param cause
* the {@code IOException}
*
* @throws NullPointerException
* if the cause is {@code null}
*/
public UncheckedIOException(String message, IOException cause) {
super(message, Objects.requireNonNull(cause));
}
/**
* Constructs an instance of this class.
*
* @param cause
* the {@code IOException}
*
* @throws NullPointerException
* if the cause is {@code null}
*/
public UncheckedIOException(IOException cause) {
super(Objects.requireNonNull(cause));
}
/**
* Returns the cause of this exception.
*
* @return the {@code IOException} which is the cause of this exception.
*/
@Override
public IOException getCause() {
return (IOException) super.getCause();
}
/**
* Called to read the object from a stream.
*
* @throws InvalidObjectException
* if the object is invalid or has a cause that is not
* an {@code IOException}
*/
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
Throwable cause = super.getCause();
if (!(cause instanceof IOException))
throw new InvalidObjectException("Cause must be an IOException");
}
}