// 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? }
if ( !(this instanceof arguments.callee) ) throw new Error("Constructor called as a function");
function stackTrace() { var err = new Error(); return err.stack; }
@Override protected void doFinishConnect() throws Exception { throw new Error(); }
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); } }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) { throw new Error("Some application error"); } });
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); } }
@Override protected void doFinishConnect() throws Exception { if (!javaChannel().finishConnect()) { throw new Error(); } }
@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."); } }
@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."); } }
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); }
@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(); } } } }
@MessageMapping("/error") public void errorAsThrowable() { throw new Error("my cause"); }
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(); } }
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); } } }
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) { } }
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()); } }
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) { } }
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()); } }