java.lang.Exception.setStackTrace()方法的使用及代码示例

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

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

Exception.setStackTrace介绍

暂无

代码示例

代码示例来源:origin: google/j2objc

private void throwTimeoutException(StatementThread thread) throws Exception {
  Exception exception = new Exception(String.format(
      "test timed out after %d milliseconds", fTimeout));
  exception.setStackTrace(thread.getRecordedStackTrace());
  throw exception;
}

代码示例来源:origin: google/truth

private static void truncateStackTrace(Exception exception, Class<?> callingClass) {
  StackTraceElement[] original = exception.getStackTrace();
  int keep = 0;
  while (keep < original.length
    && !original[keep].getClassName().equals(callingClass.getName())) {
   keep++;
  }
  exception.setStackTrace(Arrays.copyOf(original, keep));
 }
}

代码示例来源:origin: quartz-scheduler/quartz

private Exception newPlainException(Exception e) {
  String type = e.getClass().getName();
  if(type.startsWith("java.") || type.startsWith("javax.")) {
    return e;
  } else {
    Exception result = new Exception(e.getMessage());
    result.setStackTrace(e.getStackTrace());
    return result;
  }
}

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

@Override
public final Exception componentInstanceNotAvailable(final InterceptorContext interceptorContext) {
  final Exception result = new Exception(String.format(getLoggingLocale(), componentInstanceNotAvailable$str(), interceptorContext));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String failToObtainLock = "WFLYEJB0228: EJB 3.1 FR 4.3.14.1 concurrent access timeout on %s - could not obtain lock within %s %s";

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

@Override
public final Exception iterationCountOutOfRange(final String iteration) {
  final Exception result = new Exception(String.format(getLoggingLocale(), iterationCountOutOfRange$str(), iteration));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String saltWrongLength = "WFLYSEC0044: Salt has to be exactly 8 characters long.";

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

@Override
public final Exception encryptionDirectoryDoesNotExist(final String directory) {
  final Exception result = new Exception(String.format(getLoggingLocale(), encryptionDirectoryDoesNotExist$str(), directory));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String cannotCreateEncryptionDirectory = "WFLYSEC0042: Cannot create encryption directory %s";

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

@Override
public final Exception keyStoreNotWritable(final String keystoreURL) {
  final Exception result = new Exception(String.format(getLoggingLocale(), keyStoreNotWritable$str(), keystoreURL));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String keyStorePasswordNotSpecified = "WFLYSEC0039: Keystore password has to be specified.";

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

@Override
public final Exception keyStoreDoesnotExistWithExample(final String keystoreURL, final String keystoreURLExample) {
  final Exception result = new Exception(String.format(getLoggingLocale(), keyStoreDoesnotExistWithExample$str(), keystoreURL, keystoreURLExample));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String keyStoreNotWritable = "WFLYSEC0038: Keystore [%s] is not writable or not a file.";

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

@Override
public final Exception keyStorePasswordNotSpecified() {
  final Exception result = new Exception(String.format(getLoggingLocale(), keyStorePasswordNotSpecified$str()));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String encryptionDirectoryDoesNotExist = "WFLYSEC0041: Encryption directory is not a directory or doesn't exist. (%s)";

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

@Override
public final Exception cannotCreateEncryptionDirectory(final String directory) {
  final Exception result = new Exception(String.format(getLoggingLocale(), cannotCreateEncryptionDirectory$str(), directory));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String iterationCountOutOfRange = "WFLYSEC0043: Iteration count has to be within 1 - 2147483647, but it is %s.";

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

@Override
public final Exception saltWrongLength() {
  final Exception result = new Exception(String.format(getLoggingLocale(), saltWrongLength$str()));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String securityVaultException = "WFLYSEC0045: Exception encountered:";

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

@Override
public final Exception securityVaultException(final SecurityVaultException cause) {
  final Exception result = new Exception(String.format(getLoggingLocale(), securityVaultException$str()), cause);
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String vaultAliasNotSpecified = "WFLYSEC0046: Vault alias has to be specified.";

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

@Override
public final Exception vaultAliasNotSpecified() {
  final Exception result = new Exception(String.format(getLoggingLocale(), vaultAliasNotSpecified$str()));
  final StackTraceElement[] st = result.getStackTrace();
  result.setStackTrace(Arrays.copyOfRange(st, 1, st.length));
  return result;
}
private static final String vaultAttributeCreateDisplay = "WFLYSEC0047: Secured attribute value has been stored in Vault.\nPlease make note of the following:\n********************************************\nVault Block:%s\nAttribute Name:%s\nConfiguration should be done as follows:\n%s\n********************************************";

代码示例来源:origin: junit-team/junit4

private Exception createTimeoutException(Thread thread) {
  StackTraceElement[] stackTrace = thread.getStackTrace();
  final Thread stuckThread = lookForStuckThread ? getStuckThread(thread) : null;
  Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
  if (stackTrace != null) {
    currThreadException.setStackTrace(stackTrace);
    thread.interrupt();
  }
  if (stuckThread != null) {
    Exception stuckThreadException = 
      new Exception("Appears to be stuck in thread " +
              stuckThread.getName());
    stuckThreadException.setStackTrace(getStackTrace(stuckThread));
    return new MultipleFailureException(
      Arrays.<Throwable>asList(currThreadException, stuckThreadException));
  } else {
    return currThreadException;
  }
}

代码示例来源:origin: apache/incubator-druid

@Nullable
private Exception getStuckThreadException(Thread mainThread)
{
 final Thread stuckThread = getStuckThread(mainThread);
 if (stuckThread == null) {
  return null;
 }
 Exception stuckThreadException = new Exception("Appears to be stuck in thread " + stuckThread.getName());
 stuckThreadException.setStackTrace(getStackTrace(stuckThread));
 return stuckThreadException;
}

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

private static <T extends Exception> T setExceptionDetails(final T exception,
  final ForeignExceptionMessage eem) {
 final GenericExceptionMessage gem = eem.getGenericException();
 final StackTraceElement[] trace = toStackTrace(gem.getTraceList());
 exception.setStackTrace(trace);
 return exception;
}

代码示例来源:origin: apache/incubator-druid

@Nullable
private Exception getDeadlockedThreadsException()
{
 final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
 final long[] deadlockedThreadIds = threadMXBean.findDeadlockedThreads();
 if (deadlockedThreadIds == null) {
  return null;
 }
 Exception deadlockException = new Exception("Deadlocked threads:");
 for (long deadlockedThreadId : deadlockedThreadIds) {
  ThreadInfo threadInfo = threadMXBean.getThreadInfo(deadlockedThreadId);
  Exception threadException = new Exception(threadInfo.getThreadName() + " at " + threadInfo.getLockName());
  threadException.setStackTrace(threadInfo.getStackTrace());
  deadlockException.addSuppressed(threadException);
 }
 return deadlockException;
}

代码示例来源:origin: google/guava

@GwtIncompatible // lazyStackTrace
private void doTestLazyStackTraceFallback() {
 assertFalse(lazyStackTraceIsLazy());
 Exception e = new Exception();
 assertThat(lazyStackTrace(e)).containsExactly((Object[]) e.getStackTrace()).inOrder();
 try {
  lazyStackTrace(e).set(0, null);
  fail();
 } catch (UnsupportedOperationException expected) {
 }
 e.setStackTrace(new StackTraceElement[0]);
 assertThat(lazyStackTrace(e)).isEmpty();
}

代码示例来源:origin: apache/incubator-druid

private Exception createTimeoutException(Thread thread)
{
 StackTraceElement[] stackTrace = thread.getStackTrace();
 Exception currThreadException = new TestTimedOutException(timeout, timeUnit);
 if (stackTrace != null) {
  currThreadException.setStackTrace(stackTrace);
  thread.interrupt();
 }
 Exception stuckThreadException = getStuckThreadException(thread);
 Exception deadlockException = getDeadlockedThreadsException();
 if (stuckThreadException != null || deadlockException != null) {
  List<Throwable> exceptions = Stream
    .of(currThreadException, stuckThreadException, deadlockException)
    .filter(Objects::nonNull)
    .collect(Collectors.toList());
  return new MultipleFailureException(exceptions);
 } else {
  return currThreadException;
 }
}

代码示例来源:origin: google/guava

@GwtIncompatible // lazyStackTrace(Throwable)
public void testLazyStackTrace() {
 Exception e = new Exception();
 StackTraceElement[] originalStackTrace = e.getStackTrace();
 assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder();
 try {
  lazyStackTrace(e).set(0, null);
  fail();
 } catch (UnsupportedOperationException expected) {
 }
 // Now we test a property that holds only for the lazy implementation.
 if (!lazyStackTraceIsLazy()) {
  return;
 }
 e.setStackTrace(new StackTraceElement[0]);
 assertThat(lazyStackTrace(e)).containsExactly((Object[]) originalStackTrace).inOrder();
}

相关文章