Mercurial Hosting > luan
comparison core/src/luan/LuanException.java @ 646:cdc70de628b5
simplify LuanException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2016 19:58:39 -0600 |
parents | 859c0dedc8b6 |
children | 0c334975d526 |
comparison
equal
deleted
inserted
replaced
645:859c0dedc8b6 | 646:cdc70de628b5 |
---|---|
5 | 5 |
6 | 6 |
7 public final class LuanException extends Exception implements DeepCloneable { | 7 public final class LuanException extends Exception implements DeepCloneable { |
8 private LuanTable table = new LuanTable(); | 8 private LuanTable table = new LuanTable(); |
9 | 9 |
10 private LuanException(String msg,Throwable cause) { | 10 public LuanException(String msg,Throwable cause) { |
11 super(msg,cause); | 11 super(msg,cause); |
12 setTable(); | |
12 } | 13 } |
13 | 14 |
14 public LuanException(LuanState luan,Object msg) throws LuanException { | 15 public LuanException(String msg) { |
15 this( luan.toString(msg), msg instanceof Throwable ? (Throwable)msg : null ); | 16 super(msg); |
17 setTable(); | |
18 } | |
19 | |
20 public LuanException(Throwable cause) { | |
21 super(cause); | |
22 setTable(); | |
23 } | |
24 | |
25 private void setTable() { | |
16 table.rawPut( "java", this ); | 26 table.rawPut( "java", this ); |
17 table.rawPut( "message", msg ); | |
18 table.rawPut( "message_string", luan.toString(msg) ); | |
19 /* | 27 /* |
20 for( StackTraceElement ste : luan.stackTrace ) { | 28 for( StackTraceElement ste : luan.stackTrace ) { |
21 LuanTable tbl = new LuanTable(); | 29 LuanTable tbl = new LuanTable(); |
22 tbl.rawPut( "source", ste.call.source.name ); | 30 tbl.rawPut( "source", ste.call.source.name ); |
23 tbl.rawPut( "line", ste.call.lineNumber() ); | 31 tbl.rawPut( "line", ste.call.lineNumber() ); |
26 } | 34 } |
27 */ | 35 */ |
28 LuanTable metatable = new LuanTable(); | 36 LuanTable metatable = new LuanTable(); |
29 table.setMetatable(metatable); | 37 table.setMetatable(metatable); |
30 try { | 38 try { |
39 table.rawPut( "get_message", new LuanJavaFunction( | |
40 LuanException.class.getMethod( "getMessage" ), this | |
41 ) ); | |
31 table.rawPut( "throw", new LuanJavaFunction( | 42 table.rawPut( "throw", new LuanJavaFunction( |
32 LuanException.class.getMethod( "throwThis" ), this | 43 LuanException.class.getMethod( "throwThis" ), this |
33 ) ); | 44 ) ); |
34 metatable.rawPut( "__to_string", new LuanJavaFunction( | 45 metatable.rawPut( "__to_string", new LuanJavaFunction( |
35 LuanException.class.getMethod( "__to_string", LuanTable.class ), null | 46 LuanException.class.getMethod( "__to_string", LuanTable.class ), null |