java.lang.IllegalStateException.initCause()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(182)

本文整理了Java中java.lang.IllegalStateException.initCause()方法的一些代码示例,展示了IllegalStateException.initCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IllegalStateException.initCause()方法的具体详情如下:
包路径:java.lang.IllegalStateException
类名称:IllegalStateException
方法名:initCause

IllegalStateException.initCause介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

private void ensureValid(SharedClassObject obj)
throws IllegalStateException {
  if (invalid != null) {
    String msg;
    if (obj != null) {
      msg = obj.toString();
    } else {
      msg = "<unknown object>"; // NOI18N
    }
    throw (IllegalStateException) new IllegalStateException(msg).initCause(invalid);
  }
   // else fine
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public synchronized Object setProperty(String key, String value) {
  if (propertReadAt.containsKey(key) && !value.equals(super.getProperty(key))) {
    IllegalStateException e = new IllegalStateException("Changing property '" + key + "' to '" + value
        + "' after it has already been read as '" + super.getProperty(key) + "'");
    e.initCause(propertReadAt.get(key));
    throw e;
  }
  return super.setProperty(key, value);
}

代码示例来源:origin: FudanNLP/fnlp

public String getEncoding() {
 if (!isInited) {
   try {
    init();
   } catch (IOException ex) {
    IllegalStateException ise = new IllegalStateException("Init method failed.");
    ise.initCause(ise);
    throw ise;
   }
 }
 return encoding;
}

代码示例来源:origin: apache/activemq

@Override
  public void release() {
    try {
      tx.rollback();
    } catch (IOException unexpected) {
      IllegalStateException e = new IllegalStateException(unexpected);
      e.initCause(unexpected);
      throw e;
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

private <Analysis> Analysis getMethodAnalysisNoException(Class<Analysis> analysisClass, Method method) {
  try {
    return getMethodAnalysis(analysisClass, method);
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("should not happen");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: spotbugs/spotbugs

private <Analysis> Analysis getMethodAnalysisNoDataflowAnalysisException(Class<Analysis> analysisClass, Method method)
    throws CFGBuilderException {
  try {
    return getMethodAnalysis(analysisClass, method);
  } catch (CFGBuilderException e) {
    throw e;
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("should not happen");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: apache/geode

/**
 * Returns the {@linkplain InetAddress#getCanonicalHostName canonical name} of the local machine.
 */
protected static String getLocalHostName() {
 try {
  return SocketCreator.getLocalHost().getCanonicalHostName();
 } catch (UnknownHostException ex) {
  IllegalStateException ex2 = new IllegalStateException(
    "Could not determine localhost?!");
  ex2.initCause(ex);
  throw ex2;
 }
}

代码示例来源:origin: spotbugs/spotbugs

private <Analysis> Analysis getClassAnalysisNoException(Class<Analysis> analysisClass) {
  try {
    return getClassAnalysis(analysisClass);
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("should not happen");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: apache/activemq

@Override
public void remove() {
  try {
    synchronized (indexLock) {
      tx.execute(new Transaction.Closure<IOException>() {
        @Override
        public void execute(Transaction tx) throws IOException {
          iterator.remove();
        }
      });
    }
  } catch (IOException unexpected) {
    IllegalStateException e = new IllegalStateException(unexpected);
    e.initCause(unexpected);
    throw e;
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

private void tryToInitialize(SharedClassObject obj)
throws IllegalStateException {
  initializeInProgress = true;
  obj.initializeSuper = false;
  try {
    obj.initialize();
  } catch (Exception e) {
    invalid = e;
    throw (IllegalStateException) new IllegalStateException(invalid.toString() + " from " + obj).initCause(invalid); // NOI18N
  } catch (LinkageError e) {
    invalid = e;
    throw (IllegalStateException) new IllegalStateException(invalid.toString() + " from " + obj).initCause(invalid); // NOI18N
  } finally {
    initializeInProgress = false;
  }
  if (!obj.initializeSuper) {
    String msg = "You must call super.initialize() from " + obj.getClass().getName() + ".initialize()"; // NOI18N
    err.warning(msg);
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public <E> void eagerlyPutMethodAnalysis(Class<E> analysisClass, @Nonnull MethodDescriptor methodDescriptor, E analysisObject) {
  try {
    ClassContext classContext = getClassAnalysis(ClassContext.class, methodDescriptor.getClassDescriptor());
    assert analysisClass.isInstance(analysisObject);
    classContext.putMethodAnalysis(analysisClass, methodDescriptor, analysisObject);
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("Unexpected exception adding method analysis to cache");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void purgeMethodAnalyses(@Nonnull MethodDescriptor methodDescriptor) {
  try {
    ClassContext classContext = getClassAnalysis(ClassContext.class, methodDescriptor.getClassDescriptor());
    classContext.purgeMethodAnalyses(methodDescriptor);
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("Unexpected exception purging method analyses from cache");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: spotbugs/spotbugs

private <Analysis> Analysis getMethodAnalysis(Class<Analysis> analysisClass, Method method) throws DataflowAnalysisException,
CFGBuilderException {
  try {
    MethodDescriptor methodDescriptor = BCELUtil.getMethodDescriptor(jclass, method);
    return Global.getAnalysisCache().getMethodAnalysis(analysisClass, methodDescriptor);
  } catch (DataflowAnalysisException e) {
    throw e;
  } catch (CFGBuilderException e) {
    throw e;
  } catch (CheckedAnalysisException e) {
    Throwable cause = e.getCause();
    if (cause instanceof CFGBuilderException) {
      throw (CFGBuilderException) cause;
    }
    String message = "Should not happen: bad CAE: " + e.getClass().getName() + " for " + analysisClass.getName() + " of " + method;
    IllegalStateException ise = new IllegalStateException(message);
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: liuyangming/ByteTCC

public void afterReceiveRequest(TransactionRequest request) throws IllegalStateException {
  TransactionContext srcTransactionContext = request.getTransactionContext();
  if (srcTransactionContext == null) {
    return;
  }
  TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();
  TransactionContext transactionContext = srcTransactionContext.clone();
  transactionContext.setPropagatedBy(srcTransactionContext.getPropagatedBy());
  try {
    compensableCoordinator.start(transactionContext, XAResource.TMNOFLAGS);
  } catch (XAException ex) {
    logger.error("CompensableInterceptorImpl.afterReceiveRequest({})", request, ex);
    IllegalStateException exception = new IllegalStateException();
    exception.initCause(ex);
    throw exception;
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

ex.initCause(anEx);
Exceptions.attachLocalizedMessage(ex, "Cannot createClone for " + this); // NOI18N

代码示例来源:origin: line/armeria

@Override
  public void unaryCall(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
    IllegalStateException e1 = new IllegalStateException("Exception 1");
    IllegalArgumentException e2 = new IllegalArgumentException();
    AssertionError e3 = new AssertionError("Exception 3");
    Exceptions.clearTrace(e3);
    RuntimeException e4 = new RuntimeException("Exception 4");
    e1.initCause(e2);
    e2.initCause(e3);
    e3.initCause(e4);
    Status status = Status.ABORTED.withCause(e1);
    responseObserver.onError(status.asRuntimeException());
  }
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * Get the ClassContext for a class.
 *
 * @param javaClass
 *            the class
 * @return the ClassContext for that class
 */
public ClassContext getClassContext(JavaClass javaClass) {
  // This is a bit silly since we're doing an unnecessary
  // ClassDescriptor->JavaClass lookup.
  // However, we can be assured that it will succeed.
  ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(
      ClassName.toSlashedClassName(javaClass.getClassName()));
  try {
    return Global.getAnalysisCache().getClassAnalysis(ClassContext.class, classDescriptor);
  } catch (CheckedAnalysisException e) {
    IllegalStateException ise = new IllegalStateException("Could not get ClassContext for JavaClass");
    ise.initCause(e);
    throw ise;
  }
}

代码示例来源:origin: liuyangming/ByteTCC

case XAException.XAER_NOTA:
  IllegalStateException stateEx = new IllegalStateException();
  stateEx.initCause(xaex);
  throw stateEx;
case XAException.XAER_INVAL:
  IllegalStateException error = new IllegalStateException();
  error.initCause(xaex);
  throw error;
case XAException.XAER_RMERR:

代码示例来源:origin: liuyangming/ByteTCC

public void beforeSendResponse(TransactionResponse response) throws IllegalStateException {
  CompensableManager compensableManager = this.beanFactory.getCompensableManager();
  CompensableTransaction transaction = compensableManager.getCompensableTransactionQuietly();
  if (transaction == null) {
    return;
  }
  TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();
  TransactionContext srcTransactionContext = transaction.getTransactionContext();
  TransactionContext transactionContext = srcTransactionContext.clone();
  transactionContext.setPropagatedBy(srcTransactionContext.getPropagatedBy());
  response.setTransactionContext(transactionContext);
  try {
    compensableCoordinator.end(transactionContext, XAResource.TMSUCCESS);
  } catch (XAException ex) {
    logger.error("CompensableInterceptorImpl.beforeSendResponse({})", response, ex);
    IllegalStateException exception = new IllegalStateException();
    exception.initCause(ex);
    throw exception;
  }
}

代码示例来源:origin: apache/activemq

} catch (Exception e) {
  IllegalStateException ise = new IllegalStateException("Could not configure WireFormatInfo");
  ise.initCause(e);
  throw ise;

相关文章