dxexception.java

来自「Java的面向对象数据库系统的源代码」· Java 代码 · 共 90 行

JAVA
90
字号
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id: DxException.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $package org.ozoneDB.DxLib;import java.lang.reflect.*;import java.io.*;/** * Diese Klasse dient dazu, ein Java-Exception in einem Stream zu schreiben * bzw. daraus zu lesen. Das ist z.B. fuer Socket-Verbindungen nuetzlich. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $ */public class DxException extends DxObject implements Externalizable {    final static long serialVersionUID = 1L;    Throwable exc;    String msg;    public DxException() {        msg = new String();    }    public DxException( Throwable e ) {        exc = e;        msg = new String( e.toString() );    }    public Throwable toExc() {        return exc;    }    public String toString() {        return msg;    }    public void writeExternal( ObjectOutput out ) throws IOException {        try {            if (exc != null) {                out.writeUTF( exc.getClass().getName() );            } else {                out.writeUTF( "null" );            }            out.writeUTF( msg );        } catch (Exception e) {            throw new IOException( e.toString() );        }    }    public void readExternal( ObjectInput in ) throws IOException {        try {            String e = in.readUTF();            msg = in.readUTF();            if (e.compareTo( "null" ) != 0) {                Class[] classes = new Class[1];                classes[0] = e.getClass();                //Constructor constr = Class.forName( e ).getConstructor( classes );                // todo: uncommented until verified that it works                // todo: maybe we should use ClassManager here instead ot Thread.currentThread...?                Constructor constr = Thread.currentThread().getContextClassLoader().loadClass( e ).getConstructor( classes );                if (constr != null) {                    Object[] args = new Object[1];                    args[0] = msg;                    System.out.println( args[0] );                    exc = (Throwable)constr.newInstance( args );                }            }        } catch (Exception e) {            throw new IOException( e.toString() );        }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?