capture
[rrq/gorite.git] / com / intendico / gorite / GoriteError.java
1 package com.intendico.gorite;
2
3 /**
4  * This is a specialozed {@link Error} that used for wrapping
5  * exceptions in a gorite intention chain, so as to give better
6  * guidance about where in the source execution the error occurs.
7  */
8 public class GoriteError extends Error {
9
10     /**
11      * Constructor.
12      */
13     public GoriteError(Goal.Instance instance,Throwable cause) {
14         super( "Uncaught Throwable" );
15         if ( cause instanceof GoriteError ) {
16             cause = cause.getCause();
17         }
18
19         // Reduce the stack trace for the cause in a good way...
20         StackTraceElement [] stack = getStackTrace();
21         StackTraceElement [] inner = cause.getStackTrace();
22         
23         int at = inner.length - stack.length;
24         StackTraceElement created = instance.getGoal().created;
25         inner[ at ] = new StackTraceElement(
26             created.getClassName(),
27             created.getMethodName() +
28             "|" + instance.getGoal().getGoalName() + "|" + instance.head,
29             created.getFileName(),
30             created.getLineNumber() );
31         cause.setStackTrace( inner );
32         initCause( cause );
33     }
34
35 }