diff options
author | jfrijters <jfrijters> | 2004-06-17 16:01:54 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2004-06-17 16:01:54 +0400 |
commit | 762e560da0010872e8742cc7ac872071921e3308 (patch) | |
tree | b86c33285382876aaa1ed65aaa440738a46f7024 /classpath/java/lang/ExceptionHelper.java | |
parent | 5c01368207d9ad7539e259e8ca0bc136cfee6b8a (diff) |
*** empty log message ***
Diffstat (limited to 'classpath/java/lang/ExceptionHelper.java')
-rw-r--r-- | classpath/java/lang/ExceptionHelper.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/classpath/java/lang/ExceptionHelper.java b/classpath/java/lang/ExceptionHelper.java index 7ec96534..da2f2008 100644 --- a/classpath/java/lang/ExceptionHelper.java +++ b/classpath/java/lang/ExceptionHelper.java @@ -23,6 +23,9 @@ */ package java.lang; +import java.io.*; +import java.lang.reflect.*; + public final class ExceptionHelper { // the contents of the NULL_STRING should be empty (because when the exception propagates to other .NET code @@ -53,6 +56,11 @@ public final class ExceptionHelper } } + Throwable getCauseForSerialization(Throwable t) + { + return cause == CAUSE_NOT_SET ? t : cause; + } + Throwable get_Cause() { return cause == CAUSE_NOT_SET ? null : cause; @@ -426,4 +434,53 @@ public final class ExceptionHelper } return handler.IsInstanceOfType(t) ? t : null; } + + static ObjectStreamField[] getPersistentFields() + { + return new ObjectStreamField[] { + new ObjectStreamField("detailMessage", String.class), + new ObjectStreamField("cause", Throwable.class), + new ObjectStreamField("stackTrace", StackTraceElement[].class) + }; + } + + static void writeObject(Throwable t, ObjectOutputStream s) throws IOException + { + ObjectOutputStream.PutField fields = s.putFields(); + fields.put("detailMessage", t.getMessage()); + Throwable cause; + ExceptionInfoHelper eih = (ExceptionInfoHelper)exceptions.get(t); + if(eih == null) + { + cause = ((cli.System.Exception)t).get_InnerException(); + } + else + { + // TODO we need to use getCauseForSerialization, but Classpath 0.09 has a bug that + // causes infinite recursion if we try to save a reference to this here (which + // happens if cause was uninitialized [it gets set to 'this' to signal that]) + cause = eih.get_Cause(); + //cause = eih.getCauseForSerialization(t); + } + fields.put("cause", cause); + fields.put("stackTrace", t.getStackTrace()); + s.writeFields(); + } + + static void readObject(Throwable t, ObjectInputStream s) throws IOException + { + ObjectInputStream.GetField fields = null; + try + { + fields = s.readFields(); + } + catch(ClassNotFoundException x) + { + throw new IOException(x.getMessage()); + } + initThrowable(t, fields.get("detailMessage", null), fields.get("cause", null)); + setStackTrace(t, (StackTraceElement[])fields.get("stackTrace", null)); + } + + private static native void initThrowable(Object throwable, Object detailMessage, Object cause); } |