Added safeToString() for those times when you're feeling extremely robust.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@554 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-02-02 09:51:19 +00:00
parent d0c169f673
commit f08bc39cfe
2 changed files with 21 additions and 1 deletions
+4
View File
@@ -1,6 +1,10 @@
samskivert notes -*- mode: outline -*-
* To do:
Modify JORA such that if it doesn't find a matching public field in the
persistence object, it looks for getter/setter methods that will handle
the encoding/decoding of the composite fields during persistification.
Add support to the build system for enabling and disabling packages so
that people can build just what they want and not have to track down
support libraries for, say, WebMacro if they don't want the WebMacro
@@ -1,5 +1,5 @@
//
// $Id: StringUtil.java,v 1.21 2002/02/02 00:03:14 mdb Exp $
// $Id: StringUtil.java,v 1.22 2002/02/02 09:51:19 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -298,6 +298,22 @@ public class StringUtil
return buf.append("]").toString();
}
/**
* Attempts to generate a string representation of the object using
* <code>object.toString()</code>, but catches any exceptions that are
* thrown and reports them in the returned string instead. Useful for
* situations where you can't trust the rat bastards that implemented
* the object you're toString()ing.
*/
public static String safeToString (Object object)
{
try {
return object.toString();
} catch (Exception e) {
return "<toString() failure: " + e + ">";
}
}
/**
* Generates a string from the supplied bytes that is the HEX encoded
* representation of those bytes.