1 9 package org.ozoneDB.DxLib; 10 11 import java.lang.reflect.*; 12 import java.io.*; 13 14 22 public class DxException extends DxObject implements Externalizable { 23 24 final static long serialVersionUID = 1L; 25 26 Throwable exc; 27 String msg; 28 29 30 public DxException() { 31 msg = new String (); 32 } 33 34 35 public DxException( Throwable e ) { 36 exc = e; 37 msg = new String ( e.toString() ); 38 } 39 40 41 public Throwable toExc() { 42 return exc; 43 } 44 45 46 public String toString() { 47 return msg; 48 } 49 50 51 public void writeExternal( ObjectOutput out ) throws IOException { 52 try { 53 if (exc != null) { 54 out.writeUTF( exc.getClass().getName() ); 55 } else { 56 out.writeUTF( "null" ); 57 } 58 out.writeUTF( msg ); 59 } catch (Exception e) { 60 throw new IOException( e.toString() ); 61 } 62 } 63 64 65 public void readExternal( ObjectInput in ) throws IOException { 66 try { 67 String e = in.readUTF(); 68 msg = in.readUTF(); 69 if (e.compareTo( "null" ) != 0) { 70 Class [] classes = new Class [1]; 71 classes[0] = e.getClass(); 72 73 Constructor constr = Thread.currentThread().getContextClassLoader().loadClass( e ).getConstructor( classes ); 77 78 if (constr != null) { 79 Object [] args = new Object [1]; 80 args[0] = msg; 81 System.out.println( args[0] ); 82 exc = (Throwable )constr.newInstance( args ); 83 } 84 } 85 } catch (Exception e) { 86 throw new IOException( e.toString() ); 87 } 88 } 89 } 90 | Popular Tags |