org.erights.e.develop.exception
Class ThrowableSugar

java.lang.Object
  |
  +--org.erights.e.develop.exception.ThrowableSugar

public class ThrowableSugar
extends Object

Untamed: A sweetener defining extra messages that may be e-sent to a Throwable

Author:
Mark S. Miller

Field Summary
static String ProblemIndent
          Enabled: Same number of spaces as in the ProblemPrefix
static String ProblemPrefix
          Enabled: the standard "problem: " prefix
 
Constructor Summary
private ThrowableSugar()
          prevents instantiation
 
Method Summary
static RuntimeException backtrace(Throwable self, String optMsg)
          Enabled: Returns self annotated by `*** $optMsg`.
static String eStack(Throwable self)
          Enabled: Returns the backtrace annotations wrapping the leaf exception, one per line.
static String javaStack(Throwable self)
          Enabled: Returns the java backtrace stack of the leaf throwable with all newlines as '\n's.
static Throwable leaf(Throwable self)
          Enabled: Return the non-wrapping throwable at the end of a wrapping chain
static void printThrowableOn(Throwable self, Writer out)
          Enabled: In general, a Throwable prints as 'problem: '.
static Throwable unwrap(Throwable self)
          Enabled: Returns the Throwable wrapped by self.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ProblemPrefix

public static final String ProblemPrefix
Enabled: the standard "problem: " prefix


ProblemIndent

public static final String ProblemIndent
Enabled: Same number of spaces as in the ProblemPrefix

Constructor Detail

ThrowableSugar

private ThrowableSugar()
prevents instantiation

Method Detail

printThrowableOn

public static void printThrowableOn(Throwable self,
                                    Writer out)
Enabled: In general, a Throwable prints as 'problem: '.

If the msg is null, then prints as just 'problem: '. If msg contains multiple lines, the remaining lines are indented to line up with the " If self is an instance of RuntimeException, but not of any subclass of RuntimeException, then it prints as 'problem: msg' (since the type RuntimeException isn't interesting). This behavior really should be in a separate RuntimeExceptionSugar class, but is placed here to avoid creating that sugar class for only this purpose.

This really should be '__printOn', but because of layering issues, we rename it and make a special case in the MirandaMethods.__printOn().


unwrap

public static Throwable unwrap(Throwable self)
Enabled: Returns the Throwable wrapped by self. If self doesn't wrap a Throwable, return null.


leaf

public static Throwable leaf(Throwable self)
Enabled: Return the non-wrapping throwable at the end of a wrapping chain


eStack

public static String eStack(Throwable self)
Enabled: Returns the backtrace annotations wrapping the leaf exception, one per line. Empty backtrace annotations are skipped. Each line is *preceded* by a newline.


backtrace

public static RuntimeException backtrace(Throwable self,
                                         String optMsg)
Enabled: Returns self annotated by `*** $optMsg`.

Parameters:
optMsg - may equivalently be null or "", in which case it will be ignored by eStack().

javaStack

public static String javaStack(Throwable self)
Enabled: Returns the java backtrace stack of the leaf throwable with all newlines as '\n's.



comments?