Turned ObjectStreamException into a nested exception so that we can

provide information on what exception caused the object serialization or
unserialization to freak out.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@464 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-16 16:44:20 +00:00
parent dec8be5d57
commit afc7b6cfbb
3 changed files with 103 additions and 12 deletions
@@ -1,5 +1,5 @@
//
// $Id: DObjectFactory.java,v 1.8 2001/10/11 04:07:52 mdb Exp $
// $Id: DObjectFactory.java,v 1.9 2001/10/16 16:44:20 mdb Exp $
package com.threerings.presents.dobj.io;
@@ -59,8 +59,8 @@ public class DObjectFactory
return dobj;
} catch (Exception e) {
String errmsg = "Unable to unserialize dobj: " + e;
throw new ObjectStreamException(errmsg);
String errmsg = "Failure unserializing dobj";
throw new ObjectStreamException(errmsg, e);
}
}
@@ -1,9 +1,14 @@
//
// $Id: ObjectStreamException.java,v 1.4 2001/10/11 04:07:52 mdb Exp $
// $Id: ObjectStreamException.java,v 1.5 2001/10/16 16:44:20 mdb Exp $
package com.threerings.presents.io;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.commons.util.exception.Nestable;
import org.apache.commons.util.exception.NestableDelegate;
/**
* The object stream exception is used to communicate an error in
@@ -12,10 +17,100 @@ import java.io.IOException;
* the nature of the error in the exception message with the assumption
* that the caller will want to raise holy hell in every case.
*/
public class ObjectStreamException extends IOException
public class ObjectStreamException
extends IOException implements Nestable
{
/**
* Constructs an object stream exception with the specified message.
*/
public ObjectStreamException (String message)
{
super(message);
}
/**
* Constructs an object stream exception with the specified message
* and causing exception.
*/
public ObjectStreamException (String message, Throwable cause)
{
super(message);
_cause = cause;
}
// documentation inherited
public Throwable getCause ()
{
return _cause;
}
// documentation inherited
public String getMessage ()
{
StringBuffer msg = new StringBuffer();
// include our message if we have one
String ourMsg = super.getMessage();
if (ourMsg != null) {
msg.append(ourMsg);
}
// and append the message from our causing exception if we've got
// one of those
if (_cause != null) {
String causeMsg = _cause.getMessage();
if (causeMsg != null) {
if (ourMsg != null) {
msg.append(": ");
}
msg.append(causeMsg);
}
}
return (msg.length() > 0 ? msg.toString() : null);
}
/**
* Prints the stack trace of this exception the the standar error
* stream.
*/
public void printStackTrace ()
{
_delegate.printStackTrace();
}
/**
* Prints the stack trace of this exception to the specified print
* stream.
*
* @param out {@link PrintStream} to use for output.
*/
public void printStackTrace (PrintStream out)
{
_delegate.printStackTrace(out);
}
// documentation inherited
public void printStackTrace (PrintWriter out)
{
_delegate.printStackTrace(out);
}
// documentation inherited
public final void printPartialStackTrace (PrintWriter out)
{
super.printStackTrace(out);
}
/**
* The helper instance which contains much of the code which we
* delegate to.
*/
protected NestableDelegate _delegate = new NestableDelegate(this);
/**
* Holds the reference to the exception or error that caused this
* exception to be thrown.
*/
protected Throwable _cause = null;
}
@@ -1,5 +1,5 @@
//
// $Id: TypedObjectFactory.java,v 1.7 2001/10/11 04:07:52 mdb Exp $
// $Id: TypedObjectFactory.java,v 1.8 2001/10/16 16:44:20 mdb Exp $
package com.threerings.presents.io;
@@ -86,13 +86,9 @@ public class TypedObjectFactory
try {
return (TypedObject)clazz.newInstance();
} catch (Throwable t) {
Log.warning("Typed object error: " + t);
Log.logStackTrace(t);
String errmsg = "Unable to instantiate typed object " +
"[class=" + clazz.getName() +
", error=" + t.getMessage() + "].";
throw new ObjectStreamException(errmsg);
"[class=" + clazz.getName() + "]";
throw new ObjectStreamException(errmsg, t);
}
}