// (c) MIT 2003.  All rights reserved.

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	DynamicError.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	July, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Dynamic error creation module
//
////////////////////////////////////////////////////////////////////////////////

package rec.util;

import java.lang.reflect.*;

public class DynamicError extends Error
{
  public static DynamicError create( String errorName )
  {
    Object o = null;

    try {
      o = ThrowableDynamicCompiler.createError(
        errorName ).newInstance();
    }
    catch( Exception e ) {
      Assert.fatal( "unable to create " + errorName );
    }

    return( (DynamicError)o );
  }

  public static DynamicError create( String errorName, String msg )
  {
    Class s = null;

    try {
      s = Class.forName( "String" );
    }
    catch( ClassNotFoundException e ) {
      Assert.fatal();
    }

    Class[] ca = new Class[1];
    ca[0] = s;

    Constructor cn = null;

    try {
      cn = ThrowableDynamicCompiler.createError(
        errorName ).getConstructor( ca );
    }
    catch( NoSuchMethodException e ) {
      Assert.fatal();
    }

    Object[] oa = new Object[1];
    oa[0] = msg;

    Object o = null;

    try {
      o = cn.newInstance( oa );
    }
    catch( Exception e ) {
      Assert.fatal();
    }

    return( (DynamicError)o );
  }

  //////////////////////////////////////////////////////////////////////////////

  public DynamicError()
  {
  }

  public DynamicError( String msg )
  {
    super( msg );
  }
}

////////////////////////////////////////////////////////////////////////////////
