comparison src/luan/LuanException.java @ 1335:e0cf0d108a77

major cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 14 Feb 2019 03:10:45 -0700
parents 25746915a241
children 221eedb0f54e
comparison
equal deleted inserted replaced
1334:c88b486a9511 1335:e0cf0d108a77
3 import java.io.StringWriter; 3 import java.io.StringWriter;
4 import java.io.PrintWriter; 4 import java.io.PrintWriter;
5 import java.io.PrintStream; 5 import java.io.PrintStream;
6 import java.util.List; 6 import java.util.List;
7 import java.util.ArrayList; 7 import java.util.ArrayList;
8 import java.util.Map;
9 import java.util.HashMap;
8 10
9 11
10 public final class LuanException extends Exception implements LuanCloneable { 12 public final class LuanException extends Exception implements LuanCloneable {
11 private LuanTable table; 13 private LuanTable table;
14 private Map extra = new HashMap();
12 15
13 public LuanException(String msg,Throwable cause) { 16 public LuanException(String msg,Throwable cause) {
14 super(msg,cause); 17 super(msg,cause);
15 } 18 }
16 19
27 } 30 }
28 31
29 @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) { 32 @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
30 LuanException clone = (LuanException)dc; 33 LuanException clone = (LuanException)dc;
31 clone.table = (LuanTable)cloner.clone(table); 34 clone.table = (LuanTable)cloner.clone(table);
35 clone.extra = (Map)cloner.clone(extra);
36 }
37
38 public void put(String key,Object value) throws LuanException {
39 if( table == null ) {
40 extra.put(key,value);
41 } else {
42 table.put(key,value);
43 }
32 } 44 }
33 45
34 public LuanTable table(Luan luan) { 46 public LuanTable table(Luan luan) {
35 if( table==null ) { 47 if( table==null ) {
36 try { 48 try {
37 LuanTable Boot = (LuanTable)luan.require("luan:Boot.luan"); 49 LuanTable Boot = (LuanTable)luan.require("luan:Boot.luan");
38 table = (LuanTable)Boot.call( "new_error_table", this ); 50 table = (LuanTable)Boot.fn("new_error_table").call(this );
51 for( Object stupid : extra.entrySet() ) {
52 Map.Entry entry = (Map.Entry)stupid;
53 table.put( entry.getKey(), entry.getValue() );
54 }
39 } catch(LuanException e) { 55 } catch(LuanException e) {
40 throw new RuntimeException(e); 56 throw new RuntimeException(e);
41 } 57 }
42 } 58 }
43 return table; 59 return table;