1 5 package com.teamkonzept.publishing.markups; 6 7 import com.teamkonzept.lib.*; 8 9 public class TKMarkupParserException extends Exception { 10 11 int pos; 12 13 public TKMarkupParserException (String msg) { 14 15 super (msg); 16 17 this.pos = -1; 18 } 19 20 public TKMarkupParserException (String msg, int pos) { 21 22 super (msg); 23 24 this.pos = pos; 25 } 26 27 public void throwAgain () throws TKMarkupParserException { 28 29 throwAgain ((String ) null,-1); 30 } 31 32 public void throwAgain (int pos) throws TKMarkupParserException { 33 34 throwAgain ((String ) null,pos); 35 } 36 37 public void throwAgain (String msg, int pos) 38 throws TKMarkupParserException { 39 40 if (this.pos >= 0) pos = this.pos; 41 42 throwAgain (this,msg,pos); 43 } 44 45 public String getMsg () { 46 47 return getMsg (null); 48 } 49 50 public String getMsg (String prefix) { 51 52 return (prefix == null ? "" : prefix)+ 53 (pos < 0 ? "" : "Position "+pos+": ")+ 54 demandMsg(this); 55 } 56 57 public TKVector handle (TKVector diagnostics) { 58 59 if (diagnostics == null) diagnostics = new TKVector(); 60 diagnostics.addElement(getMsg()); 61 62 return diagnostics; 63 } 64 65 private static int count = 0; 66 67 private static synchronized int countUp () { 68 69 return ++count; 70 } 71 72 public static void throwAgain (Exception ex) throws TKMarkupParserException { 73 74 throwAgain (ex,(String ) null,-1); 75 } 76 77 public static void throwAgain (Exception ex, int pos) throws TKMarkupParserException { 78 79 throwAgain (ex,(String ) null,pos); 80 } 81 82 public static void throwAgain (Exception ex, String msg, int pos) 83 throws TKMarkupParserException { 84 85 String old = demandMsg(ex); 86 87 if (msg == null) throw new TKMarkupParserException (old,pos); 88 else throw new TKMarkupParserException (msg+": "+old,pos); 89 } 90 91 public static String demandMsg (Exception ex) { 92 93 String msg = ex.getMessage(); 94 95 if (msg == null) { 96 97 int id = countUp(); 98 msg = "Unbekannter Fehler #"+id+" (siehe Logfile)"; 99 } 100 101 return msg; 102 } 103 104 public static TKVector handle (Exception ex, TKVector diagnostics) { 105 106 if (diagnostics == null) diagnostics = new TKVector(); 107 diagnostics.addElement(demandMsg(ex)); 108 109 return diagnostics; 110 } 111 } 112 113 | Popular Tags |