001 package railo.runtime.exp; 002 003 import railo.runtime.Info; 004 import railo.runtime.PageContext; 005 import railo.runtime.dump.DumpData; 006 import railo.runtime.dump.DumpProperties; 007 import railo.runtime.dump.DumpTable; 008 import railo.runtime.op.Caster; 009 import railo.runtime.reflection.Reflector; 010 011 012 /** 013 * Box a Native Exception, Native = !PageException 014 */ 015 public class NativeException extends PageExceptionImpl { 016 017 private static final long serialVersionUID = 6221156691846424801L; 018 019 private Throwable t; 020 021 /** 022 * Standart constructor for native Exception class 023 * @param t Throwable 024 */ 025 public NativeException(Throwable t) { 026 super(t,t.getClass().getName()); 027 this.t=t; 028 StackTraceElement[] st = t.getStackTrace(); 029 if(hasRailoRuntime(st))setStackTrace(st); 030 else { 031 StackTraceElement[] cst = new Exception("Stack trace").getStackTrace(); 032 if(hasRailoRuntime(cst)){ 033 StackTraceElement[] mst=new StackTraceElement[st.length+cst.length-1]; 034 System.arraycopy(st, 0, mst, 0, st.length); 035 System.arraycopy(cst, 1, mst, st.length, cst.length-1); 036 037 setStackTrace(mst); 038 } 039 else setStackTrace(st); 040 } 041 setAdditional("Cause", t.getClass().getName()); 042 } 043 044 private boolean hasRailoRuntime(StackTraceElement[] st) { 045 if(st!=null)for(int i=0;i<st.length;i++){ 046 if(st[i].getClassName().indexOf("railo.runtime")!=-1) return true; 047 } 048 return false; 049 } 050 051 /** 052 * @see railo.runtime.dump.Dumpable#toDumpData(railo.runtime.PageContext, int) 053 */ 054 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 055 DumpData data = super.toDumpData(pageContext, maxlevel,dp); 056 if(data instanceof DumpTable) 057 ((DumpTable)data).setTitle("Railo ["+Info.getVersionAsString()+"] - Error ("+Caster.toClassName(t)+")"); 058 059 return data; 060 } 061 062 /** 063 * @see railo.runtime.exp.IPageException#typeEqual(java.lang.String) 064 */ 065 public boolean typeEqual(String type) { 066 if(super.typeEqual(type))return true; 067 return Reflector.isInstaneOfIgnoreCase(t.getClass(),type); 068 } 069 070 /** 071 * @see railo.runtime.exp.PageExceptionImpl#setAdditional(java.lang.String, java.lang.Object) 072 */ 073 public void setAdditional(String key, Object value) { 074 super.setAdditional(key, value); 075 } 076 }