comparison src/luan/LuanException.java @ 48:64ecb7a3aad7

rename Lua to Luan git-svn-id: https://luan-java.googlecode.com/svn/trunk@49 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Fri, 28 Dec 2012 03:29:12 +0000
parents src/luan/LuaException.java@57054fa43189
children 8ede219cd111
comparison
equal deleted inserted replaced
47:659c7139e903 48:64ecb7a3aad7
1 package luan;
2
3
4 public class LuanException extends Exception {
5 private final String stackTrace;
6
7 public LuanException(LuanState lua,LuanElement el,Object msg) {
8 super(message(msg),cause(msg));
9 stackTrace = stackTrace(lua,el,msg);
10 }
11
12 @Override public String getMessage() {
13 return super.getMessage() + stackTrace;
14 }
15
16 private String message() {
17 return super.getMessage();
18 }
19
20 private static Throwable cause(Object msg) {
21 return msg instanceof Throwable ? (Throwable)msg : null;
22 }
23
24 private static String message(Object msg) {
25 if( msg instanceof LuanException ) {
26 LuanException le = (LuanException)msg;
27 return le.message();
28 /*
29 } else if( msg instanceof Throwable ) {
30 Throwable t = (Throwable)msg;
31 return t.getMessage();
32 */
33 } else {
34 return msg.toString();
35 }
36 }
37
38 private static String stackTrace(LuanState lua,LuanElement el,Object msg) {
39 StringBuilder buf = new StringBuilder();
40 for( int i = lua.stackTrace.size() - 1; i>=0; i-- ) {
41 StackTraceElement stackTraceElement = lua.stackTrace.get(i);
42 buf.append( "\n\t" ).append( el.toString(stackTraceElement.fnName) );
43 el = stackTraceElement.call;
44 }
45 if( msg instanceof LuanException ) {
46 LuanException le = (LuanException)msg;
47 buf.append( "\ncaused by:" ).append( le.stackTrace );
48 }
49 return buf.toString();
50 }
51 }