FileDocCategorySizeDatePackage
ExceptionWithContext.javaAPI DocAndroid 1.5 API4019Wed May 06 22:41:02 BST 2009com.android.dx.util

ExceptionWithContext

public class ExceptionWithContext extends RuntimeException
Exception which carries around structured context.

Fields Summary
private StringBuffer
context
non-null; human-oriented context of the exception
Constructors Summary
public ExceptionWithContext(String message)
Constructs an instance.

param
message human-oriented message

        this(message, null);
    
public ExceptionWithContext(Throwable cause)
Constructs an instance.

param
cause null-ok; exception that caused this one

        this(null, cause);
    
public ExceptionWithContext(String message, Throwable cause)
Constructs an instance.

param
message human-oriented message
param
cause null-ok; exception that caused this one

        super((message != null) ? message :
              (cause != null) ? cause.getMessage() : null,
              cause);

        if (cause instanceof ExceptionWithContext) {
            String ctx = ((ExceptionWithContext) cause).context.toString();
            context = new StringBuffer(ctx.length() + 200);
            context.append(ctx);
        } else {
            context = new StringBuffer(200);
        }
    
Methods Summary
public voidaddContext(java.lang.String str)
Adds a line of context to this instance.

param
str non-null; new context

        if (str == null) {
            throw new NullPointerException("str == null");
        }

        context.append(str);
        if (!str.endsWith("\n")) {
            context.append('\n");
        }
    
public java.lang.StringgetContext()
Gets the context.

return
non-null; the context

        return context.toString();
    
public voidprintContext(java.io.PrintWriter out)
Prints the message and context.

param
out non-null; where to print to

        out.println(getMessage());
        out.print(context);
    
public voidprintContext(java.io.PrintStream out)
Prints the message and context.

param
out non-null; where to print to

        out.println(getMessage());
        out.print(context);
    
public voidprintStackTrace(java.io.PrintStream out)
{@inheritDoc}

        super.printStackTrace(out);
        out.println(context);
    
public voidprintStackTrace(java.io.PrintWriter out)
{@inheritDoc}

        super.printStackTrace(out);
        out.println(context);
    
public static com.android.dx.util.ExceptionWithContextwithContext(java.lang.Throwable ex, java.lang.String str)
Augments the given exception with the given context, and return the result. The result is either the given exception if it was an {@link ExceptionWithContext}, or a newly-constructed exception if it was not.

param
ex non-null; the exception to augment
param
str non-null; context to add
return
non-null; an appropriate instance

        ExceptionWithContext ewc;

        if (ex instanceof ExceptionWithContext) {
            ewc = (ExceptionWithContext) ex;
        } else {
            ewc = new ExceptionWithContext(ex);
        }

        ewc.addContext(str);
        return ewc;