Mercurial Hosting > luan
comparison core/src/luan/LuanException.java @ 689:51a134a8c89b
fix LuanException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Apr 2016 17:02:16 -0600 |
parents | 67dd1449e354 |
children | ca169567ce07 |
comparison
equal
deleted
inserted
replaced
688:f99f51bc5bea | 689:51a134a8c89b |
---|---|
4 import java.io.PrintWriter; | 4 import java.io.PrintWriter; |
5 import java.util.List; | 5 import java.util.List; |
6 import java.util.ArrayList; | 6 import java.util.ArrayList; |
7 | 7 |
8 | 8 |
9 public final class LuanException extends Exception { | 9 public final class LuanException extends Exception implements DeepCloneable { |
10 private LuanTable table; | |
10 | 11 |
11 public LuanException(String msg,Throwable cause) { | 12 public LuanException(String msg,Throwable cause) { |
12 super(msg,cause); | 13 super(msg,cause); |
14 initTable(); | |
13 } | 15 } |
14 | 16 |
15 public LuanException(String msg) { | 17 public LuanException(String msg) { |
16 super(msg); | 18 super(msg); |
19 initTable(); | |
17 } | 20 } |
18 | 21 |
19 public LuanException(Throwable cause) { | 22 public LuanException(Throwable cause) { |
20 super(cause); | 23 super(cause); |
24 initTable(); | |
25 } | |
26 | |
27 private LuanException(String msg,Throwable cause,int nonsense) { | |
28 super(msg,cause); | |
29 } | |
30 | |
31 @Override public LuanException shallowClone() { | |
32 return new LuanException(getMessage(),getCause(),99); | |
33 } | |
34 | |
35 @Override public void deepenClone(DeepCloneable dc,DeepCloner cloner) { | |
36 LuanException clone = (LuanException)dc; | |
37 clone.table = (LuanTable)cloner.get(table); | |
21 } | 38 } |
22 | 39 |
23 public LuanTable table() { | 40 public LuanTable table() { |
24 LuanTable table = new LuanTable(); | 41 return table; |
42 } | |
43 | |
44 private void initTable() { | |
45 table = new LuanTable(); | |
25 table.rawPut( "java", this ); | 46 table.rawPut( "java", this ); |
26 /* | |
27 for( StackTraceElement ste : luan.stackTrace ) { | |
28 LuanTable tbl = new LuanTable(); | |
29 tbl.rawPut( "source", ste.call.source.name ); | |
30 tbl.rawPut( "line", ste.call.lineNumber() ); | |
31 tbl.rawPut( "call_to", ste.fnName ); | |
32 table.rawPut( table.rawLength() + 1, tbl ); | |
33 } | |
34 */ | |
35 LuanTable metatable = new LuanTable(); | 47 LuanTable metatable = new LuanTable(); |
36 table.setMetatable(metatable); | 48 table.setMetatable(metatable); |
37 try { | 49 try { |
38 table.rawPut( "get_message", new LuanJavaFunction( | 50 table.rawPut( "get_message", new LuanJavaFunction( |
39 LuanException.class.getMethod( "getMessage" ), this | 51 LuanException.class.getMethod( "getMessage" ), this |
48 LuanException.class.getMethod( "getFullMessage" ), this | 60 LuanException.class.getMethod( "getFullMessage" ), this |
49 ) ); | 61 ) ); |
50 } catch(NoSuchMethodException e) { | 62 } catch(NoSuchMethodException e) { |
51 throw new RuntimeException(e); | 63 throw new RuntimeException(e); |
52 } | 64 } |
53 return table; | |
54 } | 65 } |
55 | 66 |
56 public void throwThis() throws LuanException { | 67 public void throwThis() throws LuanException { |
57 throw this; | 68 throw this; |
58 } | 69 } |