java.lang.Error.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(105)

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

Error.<init>介绍

[英]Constructs a new Error that includes the current stack trace.
[中]构造包含当前堆栈跟踪的新错误。

代码示例

代码示例来源:origin: stackoverflow.com

// or it's a property that can throw an error
Object.defineProperty(window, "myVariable", { 
  get: function() { throw new Error("W00t?"); }, 
  set: undefined 
});
if (myVariable) {
  // Error: W00t?
}

代码示例来源:origin: stackoverflow.com

if ( !(this instanceof arguments.callee) ) 
 throw new Error("Constructor called as a function");

代码示例来源:origin: stackoverflow.com

function stackTrace() {
  var err = new Error();
  return err.stack;
}

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

@Override
protected void doFinishConnect() throws Exception {
  throw new Error();
}

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

static byte[] allocateUninitializedArray(int size) {
  try {
    return (byte[]) ALLOCATE_ARRAY_METHOD.invoke(INTERNAL_UNSAFE, byte.class, size);
  } catch (IllegalAccessException e) {
    throw new Error(e);
  } catch (InvocationTargetException e) {
    throw new Error(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

public AntWithFindResourceClassLoader(ClassLoader parent, boolean parentFirst) {
  super(parent, parentFirst);
  try {
    Field $pathComponents = AntClassLoader.class.getDeclaredField("pathComponents");
    $pathComponents.setAccessible(true);
    pathComponents = (Vector)$pathComponents.get(this);
  } catch (NoSuchFieldException | IllegalAccessException e) {
    throw new Error(e);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  protected void doInTransactionWithoutResult(TransactionStatus status) {
    throw new Error("Some application error");
  }
});

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

static ByteBuffer newDirectBuffer(long address, int capacity) {
  ObjectUtil.checkPositiveOrZero(capacity, "capacity");
  try {
    return (ByteBuffer) DIRECT_BUFFER_CONSTRUCTOR.newInstance(address, capacity);
  } catch (Throwable cause) {
    // Not expected to ever throw!
    if (cause instanceof Error) {
      throw (Error) cause;
    }
    throw new Error(cause);
  }
}

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

@Override
protected void doFinishConnect() throws Exception {
  if (!javaChannel().finishConnect()) {
    throw new Error();
  }
}

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

@Override
protected void doFinishConnect() throws Exception {
  if (javaChannel().finishConnect()) {
    selectionKey().interestOps(
        selectionKey().interestOps() & ~OP_CONNECT);
  } else {
    throw new Error(
        "Provider error: failed to finish connect. Provider library should be upgraded.");
  }
}

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

@Override
protected void doFinishConnect() throws Exception {
  if (javaChannel().finishConnect()) {
    selectionKey().interestOps(
        selectionKey().interestOps() & ~OP_CONNECT);
  } else {
    throw new Error(
        "Provider error: failed to finish connect. Provider library should be upgraded.");
  }
}

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

public void testFutureGetThrowsWrappedError() throws Exception {
 Error error = new Error();
 inputFuture.setException(error);
 // Verify that get throws an ExecutionException, caused by an Error, when
 // the callback is called.
 listener.assertException(error);
}

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

@Override
  public void update(ByteBuf b, int off, int len) {
    if (b.hasArray()) {
      update(b.array(), b.arrayOffset() + off, len);
    } else {
      try {
        method.invoke(checksum, CompressionUtil.safeNioBuffer(b));
      } catch (Throwable cause) {
        throw new Error();
      }
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@MessageMapping("/error")
public void errorAsThrowable() {
  throw new Error("my cause");
}

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

private MemoryRegionCache<?> cache(PoolArena<?> area, int normCapacity, SizeClass sizeClass) {
  switch (sizeClass) {
  case Normal:
    return cacheForNormal(area, normCapacity);
  case Small:
    return cacheForSmall(area, normCapacity);
  case Tiny:
    return cacheForTiny(area, normCapacity);
  default:
    throw new Error();
  }
}

代码示例来源:origin: bumptech/glide

private void runTest(TestCase testCase) {
 for (Harness harness : harnesses) {
  try {
   testCase.runTest(harness);
  } catch (MockitoAssertionError e) {
   throw new Error("Failed to get expected call on " + harness, e);
  }
 }
}

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

public void testIsEmpty_map() {
 Map<Object, Object> map = new HashMap<>();
 Helpers.assertEmpty(map);
 map.put("a", "b");
 try {
  Helpers.assertEmpty(map);
  throw new Error();
 } catch (AssertionFailedError expected) {
 }
}

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

public void testAllAsList_error() throws Exception {
 Error error = new Error("deliberate");
 SettableFuture<String> future1 = SettableFuture.create();
 ListenableFuture<String> future2 = immediateFuture("results");
 ListenableFuture<List<String>> compound = allAsList(ImmutableList.of(future1, future2));
 future1.setException(error);
 try {
  getDone(compound);
  fail();
 } catch (ExecutionException expected) {
  assertSame(error, expected.getCause());
 }
}

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

public void testAssertContains() {
 List<?> list = Arrays.asList("a", "b");
 Helpers.assertContains(list, "a");
 Helpers.assertContains(list, "b");
 try {
  Helpers.assertContains(list, "c");
  throw new Error();
 } catch (AssertionFailedError expected) {
 }
}

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

public void testCatching_fallbackGeneratesError() throws Exception {
 final Error error = new Error("deliberate");
 Function<Throwable, Integer> fallback =
   new Function<Throwable, Integer>() {
    @Override
    public Integer apply(Throwable t) {
     throw error;
    }
   };
 ListenableFuture<Integer> failingFuture = immediateFailedFuture(new RuntimeException());
 try {
  getDone(catching(failingFuture, Throwable.class, fallback, directExecutor()));
  fail();
 } catch (ExecutionException expected) {
  assertSame(error, expected.getCause());
 }
}

相关文章