Java源码示例:java.lang.InstantiationException

示例1
/**
 * Loads the given messages to environment table
 */
public void loadMessages(String environmentName, String messageType, String message) throws InstantiationException {
    final int envId = environmentDao.getEnironmentIdFromName(environmentName);
    String updateQuery = null;
    if (messageType.equalsIgnoreCase(Constants.MESSAGE_TYPE_APP)) {
        updateQuery = HQLConstants.UPDATE_APP_MESSAGE;
    } else if (messageType.equalsIgnoreCase(Constants.MESSAGE_TYPE_INFRA)) {
        updateQuery = HQLConstants.UPDATE_INFRA_MESSAGE;
    } else if (messageType.equalsIgnoreCase(Constants.MESSAGE_TYPE_GENERAL)) {
        updateQuery = HQLConstants.UPDATE_GENERAL_MESSAGE;
    } else if (messageType.equalsIgnoreCase(Constants.MESSAGE_TYPE_COUNTER)) {
        updateQuery = HQLConstants.UPDATE_COUNTER_MESSAGE;
    }
    else {
        throw new IllegalArgumentException("Invalid value for Message Type : " + messageType);
    }
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    Query query = session.createQuery(updateQuery).setInteger("envId", envId).setString("message", message);
    query.executeUpdate();
    tx.commit();
    session.close();
}
 
示例2
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    InstantiationException object1 = new InstantiationException();
    harness.check(object1 != null);
    harness.check(object1.toString(), "java.lang.InstantiationException");

    InstantiationException object2 = new InstantiationException("nothing happens");
    harness.check(object2 != null);
    harness.check(object2.toString(), "java.lang.InstantiationException: nothing happens");

    InstantiationException object3 = new InstantiationException(null);
    harness.check(object3 != null);
    harness.check(object3.toString(), "java.lang.InstantiationException");

}
 
示例3
/**
 * Runs the test using the specified harness.
 *
 * @param harness  the test harness (<code>null</code> not permitted).
 */
public void test(TestHarness harness)
{
    // flag that is set when exception is caught
    boolean caught = false;
    try {
        throw new InstantiationException("InstantiationException");
    }
    catch (InstantiationException e) {
        // correct exception was caught
        caught = true;
    }
    harness.check(caught);
}