| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.os; |
| 18 |
|
| 19 |
import java.io.IOException; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class ParcelableException extends RuntimeException implements Parcelable { |
| 38 |
public ParcelableException(Throwable t) { |
| 39 |
super(t); |
| 40 |
} |
| 41 |
|
| 42 |
@SuppressWarnings("unchecked") |
| 43 |
public <T extends Throwable> void maybeRethrow(Class<T> clazz) throws T { |
| 44 |
if (clazz.isAssignableFrom(getCause().getClass())) { |
| 45 |
throw (T) getCause(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public static Throwable readFromParcel(Parcel in) { |
| 51 |
final String name = in.readString(); |
| 52 |
final String msg = in.readString(); |
| 53 |
try { |
| 54 |
final Class<?> clazz = Class.forName(name, true, Parcelable.class.getClassLoader()); |
| 55 |
if (Throwable.class.isAssignableFrom(clazz)) { |
| 56 |
return (Throwable) clazz.getConstructor(String.class).newInstance(msg); |
| 57 |
} |
| 58 |
} catch (ReflectiveOperationException e) { |
| 59 |
} |
| 60 |
return new RuntimeException(name + ": " + msg); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
public static void writeToParcel(Parcel out, Throwable t) { |
| 65 |
out.writeString(t.getClass().getName()); |
| 66 |
out.writeString(t.getMessage()); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public int describeContents() { |
| 71 |
return 0; |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public void writeToParcel(Parcel dest, int flags) { |
| 76 |
writeToParcel(dest, getCause()); |
| 77 |
} |
| 78 |
|
| 79 |
public static final @android.annotation.NonNull Creator<ParcelableException> CREATOR = new Creator<ParcelableException>() { |
| 80 |
@Override |
| 81 |
public ParcelableException createFromParcel(Parcel source) { |
| 82 |
return new ParcelableException(readFromParcel(source)); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public ParcelableException[] newArray(int size) { |
| 87 |
return new ParcelableException[size]; |
| 88 |
} |
| 89 |
}; |
| 90 |
} |