comparison src/luan/LuanException.java @ 783:4083f5a67c63

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 30 Aug 2016 12:00:38 -0600
parents 655280eab1e2
children 6a7c6879158d
comparison
equal deleted inserted replaced
782:655280eab1e2 783:4083f5a67c63
9 public final class LuanException extends Exception implements LuanCloneable { 9 public final class LuanException extends Exception implements LuanCloneable {
10 private LuanTable table; 10 private LuanTable table;
11 11
12 public LuanException(String msg,Throwable cause) { 12 public LuanException(String msg,Throwable cause) {
13 super(msg,cause); 13 super(msg,cause);
14 initTable();
15 } 14 }
16 15
17 public LuanException(String msg) { 16 public LuanException(String msg) {
18 super(msg); 17 super(msg);
19 initTable();
20 } 18 }
21 19
22 public LuanException(Throwable cause) { 20 public LuanException(Throwable cause) {
23 super(cause); 21 super(cause);
24 initTable();
25 } 22 }
26 23
27 private LuanException(String msg,Throwable cause,int nonsense) { 24 private LuanException(String msg,Throwable cause,int nonsense) {
28 super(msg,cause); 25 super(msg,cause);
29 } 26 }
36 LuanException clone = (LuanException)dc; 33 LuanException clone = (LuanException)dc;
37 clone.table = (LuanTable)cloner.clone(table); 34 clone.table = (LuanTable)cloner.clone(table);
38 } 35 }
39 36
40 public LuanTable table() { 37 public LuanTable table() {
38 if( table==null ) {
39 table = new LuanTable();
40 table.rawPut( "java", this );
41 LuanTable metatable = new LuanTable();
42 table.setMetatable(metatable);
43 try {
44 table.rawPut( "get_message", new LuanJavaFunction(
45 LuanException.class.getMethod( "getMessage" ), this
46 ) );
47 table.rawPut( "throw", new LuanJavaFunction(
48 LuanException.class.getMethod( "throwThis" ), this
49 ) );
50 table.rawPut( "get_java_stack_trace_string", new LuanJavaFunction(
51 LuanException.class.getMethod( "getJavaStackTraceString" ), this
52 ) );
53 metatable.rawPut( "__to_string", new LuanJavaFunction(
54 LuanException.class.getMethod( "getFullMessage" ), this
55 ) );
56 } catch(NoSuchMethodException e) {
57 throw new RuntimeException(e);
58 }
59 }
41 return table; 60 return table;
42 }
43
44 private void initTable() {
45 table = new LuanTable();
46 table.rawPut( "java", this );
47 LuanTable metatable = new LuanTable();
48 table.setMetatable(metatable);
49 try {
50 table.rawPut( "get_message", new LuanJavaFunction(
51 LuanException.class.getMethod( "getMessage" ), this
52 ) );
53 table.rawPut( "throw", new LuanJavaFunction(
54 LuanException.class.getMethod( "throwThis" ), this
55 ) );
56 table.rawPut( "get_java_stack_trace_string", new LuanJavaFunction(
57 LuanException.class.getMethod( "getJavaStackTraceString" ), this
58 ) );
59 metatable.rawPut( "__to_string", new LuanJavaFunction(
60 LuanException.class.getMethod( "getFullMessage" ), this
61 ) );
62 } catch(NoSuchMethodException e) {
63 throw new RuntimeException(e);
64 }
65 } 61 }
66 62
67 public void throwThis() throws LuanException { 63 public void throwThis() throws LuanException {
68 throw this; 64 throw this;
69 } 65 }