package com.sun.portal.providers;
import com.sun.portal.desktop.TypedException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* <p>This exception is a generic superclass for all provider related
* exceptions. All exceptions deliberately-thrown from a provider
* should be a subclass of this.
**/
public class ProviderException extends Exception implements TypedException{
/**
* The root cause of the exception, or null if this exception is
* the root cause.
*/
protected Throwable wrapped = null;
private String type = UNKNOWN_TYPE;
/**
* Constructs a new exception with the specified message, indicating an
* error in the provider as happened.<br><br>
*
* @param msg The descriptive message.
*/
public ProviderException(String msg) {
super(msg);
}
/**
* Constructs a new exception with the specified message, and the original
* <code>exception</code> or <code>error</code>, indicating an error in the provider as happened.<br><br>
*
* @param msg The descriptive message.
* @param e The original <code>exception</code> or <code>error</code>.
*/
public ProviderException(String msg, Throwable e) {
super(msg);
wrapped = e;
}
/**
* Constructs a new exception with the specified message and the exception type defined in TypedException interface
* So that the proper error template is shown to user.
* @param msg
* @param type
*/
public ProviderException(String msg,String type)
{
super(msg);
this.type = type;
}
/**
* Returns the <code>Throwable</code> object which is the root cause of
* the exception. It returns null if this exception is the root cause.
*/
public Throwable getWrapped() {
return wrapped;
}
/**
* Returns a descriptive message of this exception. If the <code>wrapped</code> object is
* not null, the appends the description of the wrapped object to the
* result.
*/
public String toString() {
StringBuffer b = new StringBuffer();
b.append(super.toString());
if (getWrapped() != null) {
b.append(wrapped.toString());
}
return b.toString();
}
/**
* Prints the stack backtrace. If the <code>wrapped</code> object is not null then
* it also prints the stack backtrace of that exception.
*/
public void printStackTrace() {
super.printStackTrace();
if (getWrapped() != null) {
wrapped.printStackTrace();
}
}
/**
* Prints the stack backtrace to the specified print stream.
* If the <code>wrapped</code> object is not null then it also prints the stack
* backtrace of that exception.
*/
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
if (getWrapped() != null) {
wrapped.printStackTrace(s);
}
}
/**
* Prints the stack backtrace to the specified print writer.
* If the <code>wrapped</code> object is not null then it also prints the stack
* backtrace of that exception.
*/
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
if (getWrapped() != null) {
wrapped.printStackTrace(s);
}
}
public String getType() {
return type;
}
}
|