本文整理了Java中java.lang.Exception.initCause()
方法的一些代码示例,展示了Exception.initCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exception.initCause()
方法的具体详情如下:
包路径:java.lang.Exception
类名称:Exception
方法名:initCause
暂无
代码示例来源:origin: com.h2database/h2
private static <T extends Exception> T initCause(T e, Object... arguments) {
int size = arguments.length;
if (size > 0) {
Object o = arguments[size - 1];
if (o instanceof Throwable) {
e.initCause((Throwable) o);
}
}
return e;
}
代码示例来源:origin: org.osgi/org.osgi.core
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.3
*/
@Override
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
代码示例来源:origin: org.osgi/org.osgi.core
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.3
*/
@Override
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
}
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.1
*/
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.0.1
*/
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.1
*/
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
}
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.2
*/
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
}
代码示例来源:origin: org.osgi/org.osgi.compendium
/**
* Initializes the cause of this exception to the specified value.
*
* @param cause The cause of this exception.
* @return This exception.
* @throws IllegalArgumentException If the specified cause is this
* exception.
* @throws IllegalStateException If the cause of this exception has already
* been set.
* @since 1.2
*/
public Throwable initCause(Throwable cause) {
return super.initCause(cause);
}
}
代码示例来源:origin: lealone/Lealone
private static <T extends Exception> T initCause(T e, Object... arguments) {
int size = arguments.length;
if (size > 0) {
Object o = arguments[size - 1];
if (o instanceof Exception) {
e.initCause((Exception) o);
}
}
return e;
}
代码示例来源:origin: jenkinsci/jenkins
public synchronized void abort(Throwable cause) {
interrupted = new AbortException();
if (cause!=null)
interrupted.initCause(cause);
notifyAll();
}
代码示例来源:origin: google/guava
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) {
// getConstructors() guarantees this as long as we don't modify the array.
@SuppressWarnings({"unchecked", "rawtypes"})
List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors());
for (Constructor<X> constructor : preferringStrings(constructors)) {
@Nullable X instance = newFromConstructor(constructor, cause);
if (instance != null) {
if (instance.getCause() == null) {
instance.initCause(cause);
}
return instance;
}
}
throw new IllegalArgumentException(
"No appropriate constructor for exception of type "
+ exceptionClass
+ " in response to chained exception",
cause);
}
代码示例来源:origin: prestodb/presto
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) {
// getConstructors() guarantees this as long as we don't modify the array.
@SuppressWarnings({"unchecked", "rawtypes"})
List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors());
for (Constructor<X> constructor : preferringStrings(constructors)) {
@NullableDecl X instance = newFromConstructor(constructor, cause);
if (instance != null) {
if (instance.getCause() == null) {
instance.initCause(cause);
}
return instance;
}
}
throw new IllegalArgumentException(
"No appropriate constructor for exception of type "
+ exceptionClass
+ " in response to chained exception",
cause);
}
代码示例来源:origin: google/j2objc
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) {
// getConstructors() guarantees this as long as we don't modify the array.
@SuppressWarnings({"unchecked", "rawtypes"})
List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors());
for (Constructor<X> constructor : preferringStrings(constructors)) {
@NullableDecl X instance = newFromConstructor(constructor, cause);
if (instance != null) {
if (instance.getCause() == null) {
instance.initCause(cause);
}
return instance;
}
}
throw new IllegalArgumentException(
"No appropriate constructor for exception of type "
+ exceptionClass
+ " in response to chained exception",
cause);
}
代码示例来源:origin: google/guava
public void testGetRootCause_Loop() {
Exception cause = new Exception();
Exception exception = new Exception(cause);
cause.initCause(exception);
try {
Throwables.getRootCause(cause);
fail("Should have throw IAE");
} catch (IllegalArgumentException expected) {
assertThat(expected).hasCauseThat().isSameAs(cause);
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
/**
* .
*/
@Test
public void testCircularCauseExceptions() {
final Exception e1 = new Exception();
final Exception e2 = new Exception(e1);
e1.initCause(e2);
LogManager.getLogger().error("Error", e1);
}
}
代码示例来源:origin: google/guava
public void testGetCasualChainLoop() {
Exception cause = new Exception();
Exception exception = new Exception(cause);
cause.initCause(exception);
try {
Throwables.getCausalChain(cause);
fail("Should have throw IAE");
} catch (IllegalArgumentException expected) {
assertThat(expected).hasCauseThat().isSameAs(cause);
}
}
代码示例来源:origin: apache/hive
public void testExceptionConversion() {
Exception ex1 = createException();
ex1.initCause(createSimpleCause());
Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));
Assert.assertSame(RuntimeException.class, ex.getClass());
Assert.assertEquals("exception1", ex.getMessage());
Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
Assert.assertEquals("exception2", ex.getCause().getMessage());
}
};
代码示例来源:origin: confluentinc/ksql
@Test
public void shouldHandleRecursiveExceptionChain() {
final Exception cause = new TestException("Something went wrong");
final Throwable e = new TestException("Top level", cause);
cause.initCause(e);
assertThat(
buildErrorMessage(e),
is("Top level" + System.lineSeparator()
+ "Caused by: Something went wrong")
);
}
代码示例来源:origin: apache/hive
/**
* Tests the conversion between the exception text with the simple cause and the
* Throwable object
*/
@Test
public void testExceptionMarshalling() throws Exception {
Exception ex1 = createException();
ex1.initCause(createSimpleCause());
Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1));
Assert.assertSame(RuntimeException.class, ex.getClass());
Assert.assertEquals("exception1", ex.getMessage());
Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass());
Assert.assertEquals("exception2", ex.getCause().getMessage());
}
代码示例来源:origin: apache/hive
/**
* Tests the conversion from a regular exception to the TStatus object
*/
@Test
public void testExceptionToTStatus() {
Exception ex1 = createException();
ex1.initCause(createSimpleCause());
TStatus status = HiveSQLException.toTStatus(ex1);
Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode());
Assert.assertEquals(ex1.getMessage(), status.getErrorMessage());
Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages());
}
内容来源于网络,如有侵权,请联系作者删除!