bsh
Class TargetError

java.lang.Object
java.lang.Throwable
java.lang.Exception
bsh.EvalError
bsh.TargetError
- All Implemented Interfaces:
- java.io.Serializable
- public class TargetError
- extends EvalError
TargetError is an EvalError that wraps an exception thrown by the script
(or by code called from the script). TargetErrors indicate exceptions
which can be caught within the script itself, whereas a general EvalError
indicates that the script cannot be evaluated further for some reason.
If the exception is caught within the script it is automatically unwrapped,
so the code looks like normal Java code. If the TargetError is thrown
from the eval() or interpreter.eval() method it may be caught and unwrapped
to determine what exception was thrown.
| Nested classes inherited from class java.lang.Throwable |
|
| Fields inherited from class java.lang.Exception |
|
| Fields inherited from class java.lang.Throwable |
|
target
java.lang.Throwable target
inNativeCode
boolean inNativeCode
TargetError
public TargetError(java.lang.String msg,
java.lang.Throwable t,
SimpleNode node,
CallStack callstack,
boolean inNativeCode)
TargetError
public TargetError(java.lang.Throwable t,
SimpleNode node,
CallStack callstack)
getTarget
public java.lang.Throwable getTarget()
toString
public java.lang.String toString()
- Description copied from class:
EvalError
- Print the error with line number and stack trace.
- Overrides:
toString in class EvalError
printStackTrace
public void printStackTrace()
- Description copied from class:
java.lang.Throwable
- Print a stack trace to the standard error stream. This stream is the
current contents of
System.err. The first line of output
is the result of Throwable.toString()>Throwable.toString() 55 , and the remaining lines represent
the data created by Throwable.fillInStackTrace()>Throwable.fillInStackTrace() 55 . While the format is
unspecified, this implementation uses the suggested format, demonstrated
by this example:
public class Junk
{
public static void main(String args[])
{
try
{
a();
}
catch(HighLevelException e)
{
e.printStackTrace();
}
}
static void a() throws HighLevelException
{
try
{
b();
}
catch(MidLevelException e)
{
throw new HighLevelException(e);
}
}
static void b() throws MidLevelException
{
c();
}
static void c() throws MidLevelException
{
try
{
d();
}
catch(LowLevelException e)
{
throw new MidLevelException(e);
}
}
static void d() throws LowLevelException
{
e();
}
static void e() throws LowLevelException
{
throw new LowLevelException();
}
}
class HighLevelException extends Exception
{
HighLevelException(Throwable cause) { super(cause); }
}
class MidLevelException extends Exception
{
MidLevelException(Throwable cause) { super(cause); }
}
class LowLevelException extends Exception
{
}
HighLevelException: MidLevelException: LowLevelException
at Junk.a(Junk.java:13)
at Junk.main(Junk.java:4)
Caused by: MidLevelException: LowLevelException
at Junk.c(Junk.java:23)
at Junk.b(Junk.java:17)
at Junk.a(Junk.java:11)
... 1 more
Caused by: LowLevelException
at Junk.e(Junk.java:30)
at Junk.d(Junk.java:27)
at Junk.c(Junk.java:21)
... 3 more
printStackTrace
public void printStackTrace(java.io.PrintStream out)
- Description copied from class:
java.lang.Throwable
- Print a stack trace to the specified PrintStream. See
Throwable.printStackTrace()>
Throwable.printStackTrace() 55 for the sample format.
printStackTrace
public void printStackTrace(boolean debug,
java.io.PrintStream out)
printTargetError
public java.lang.String printTargetError(java.lang.Throwable t)
- Generate a printable string showing the wrapped target exception.
If the proxy mechanism is available, allow the extended print to
check for UndeclaredThrowableException and print that embedded error.
xPrintTargetError
public java.lang.String xPrintTargetError(java.lang.Throwable t)
- Extended form of print target error.
This indirection is used to print UndeclaredThrowableExceptions
which are possible when the proxy mechanism is available.
We are shielded from compile problems by using a bsh script.
This is acceptable here because we're not in a critical path...
Otherwise we'd need yet another dynamically loaded module just for this.
inNativeCode
public boolean inNativeCode()
- Return true if the TargetError was generated from native code.
e.g. if the script called into a compiled java class which threw
the excpetion. We distinguish so that we can print the stack trace
for the native code case... the stack trace would not be useful if
the exception was generated by the script. e.g. if the script
explicitly threw an exception... (the stack trace would simply point
to the bsh internals which generated the exception).