Tabnine Logo
Exceptions
Code IndexAdd Tabnine to your IDE (free)

How to use
Exceptions
in
uk.org.lidalia.lang

Best Java code snippets using uk.org.lidalia.lang.Exceptions (Showing top 10 results out of 315)

origin: uk.org.lidalia/lidalia-lang

/**
 * @param toThrow The throwable that will be thrown, unwrapped and unchecked; must not be null
 * @throws NullPointerException if toThrow is null
 */
public static void throwUnchecked(final Throwable toThrow) {
  throwUnchecked(toThrow, null);
}
origin: uk.org.lidalia/lidalia-lang

/**
 * Because this method throws an unchecked exception, when it is called in a method with a return type the compiler
 * does not know the method is exiting, requiring a further line to return null or throw an unchecked exception
 * directly. This generified method allows this to be avoided by tricking the compiler by adding a return statement
 * as so:
 * <pre>
 *     String someMethod() {
 *         try {
 *             somethingThatThrowsException();
 *         } catch (Exception e) {
 *             return throwUnchecked(e, null); // does not actually return, throws the exception
 *         }
 *     }
 * </pre>
 * @param toThrow The throwable that will be thrown, unwrapped and unchecked; must not be null
 * @param returnType trick to persuade the compiler that a method returns appropriately - always pass null here
 * @return Never returns, always throws the passed in exception
 * @throws NullPointerException if toThrow is null
 */
public static <T> T throwUnchecked(final Throwable toThrow, final T returnType) {
  Exceptions.<RuntimeException>doThrowUnchecked(checkNotNull(toThrow));
  throw new AssertionError("This code should be unreachable. Something went terribly wrong here!");
}
origin: uk.org.lidalia/slf4j-test

  @Override
  public Properties apply(final InputStream propertyResource) {
    try (InputStream closablePropertyResource = propertyResource) {
      final Properties loadedProperties = new Properties();
      loadedProperties.load(closablePropertyResource);
      return loadedProperties;
    } catch (IOException ioException) {
      return throwUnchecked(ioException, null);
    }
  }
};
origin: Mahoney/slf4j-test

  @Override
  public Properties apply(final InputStream propertyResource) {
    try (InputStream closablePropertyResource = propertyResource) {
      final Properties loadedProperties = new Properties();
      loadedProperties.load(closablePropertyResource);
      return loadedProperties;
    } catch (IOException ioException) {
      return throwUnchecked(ioException, null);
    }
  }
};
origin: uk.org.lidalia/lidalia-lang

private FluentIterable<FieldFacade> fields() {
  try {
    return IDENTITY_FIELDS.get(getClass());
  } catch (ExecutionException e) {
    return throwUnchecked(e.getCause(), null);
  }
}
origin: uk.org.lidalia/lidalia-test

  @Override
  protected Throwable featureValueOf(final Constructor<?> constructor) {
    try {
      constructor.setAccessible(true);
      constructor.newInstance();
      return null;
    } catch (InvocationTargetException e) {
      return e.getCause();
    } catch (Exception e) {
      return throwUnchecked(e, null);
    } finally {
      constructor.setAccessible(false);
    }
  }
};
origin: uk.org.lidalia/lidalia-lang

/**
 * @throws Exception thrown by {@link #perform()} - unchecked
 */
@Override
public final void run() {
  try {
    perform();
  } catch (Exception e) {
    throwUnchecked(e);
  }
}
origin: Mahoney/sysout-over-slf4j

private static <T> T doWithSystemClasses(Callable<T> callable) throws SysOutOverSLF4JSystemJarNotPresentException {
  try {
    return callable.call();
  } catch (NoClassDefFoundError error) {
    if (error.getMessage().contains("sysoutslf4j/system")) {
      throw new SysOutOverSLF4JSystemJarNotPresentException(error);
    } else {
      throw error;
    }
  } catch (Exception e) {
    return throwUnchecked(e, null);
  }
}
origin: uk.org.lidalia/lidalia-lang

/**
 * @throws Exception thrown by the original caller, unwrapped
 * @return the result of the expression passed to the constructor; this is evaluated the first time this method is called,
 *         subsequent calls return the same result without re-evaluating it. Concurrent calls block until the first execution
 *         is complete.
 */
@Override
public T call() {
  supplier.run();
  try {
    return getUninterruptibly(supplier);
  } catch (ExecutionException e) {
    return throwUnchecked(e.getCause(), null);
  }
}
origin: uk.org.lidalia/lidalia-test

@SuppressWarnings({ "unchecked", "PMD.AvoidCatchingThrowable" })
private static <ThrowableType extends Throwable> ThrowableType shouldThrow(
    final Class<ThrowableType> expectedThrowableType,
    final Optional<String> message,
    final Runnable workThatShouldThrowThrowable) {
  try {
    workThatShouldThrowThrowable.run();
    throw new AssertionError(message.or("No exception thrown"));
  } catch (final Throwable actualThrowableThrown) {
    final Throwable trueThrowable = extractTrueThrowable(expectedThrowableType, actualThrowableThrown);
    if (!expectedThrowableType.isInstance(trueThrowable)) {
      throwUnchecked(actualThrowableThrown);
    }
    return (ThrowableType) trueThrowable;
  }
}
uk.org.lidalia.langExceptions

Javadoc

Static utility functions around Exception management.

Most used methods

  • throwUnchecked
    Because this method throws an unchecked exception, when it is called in a method with a return type
  • doThrowUnchecked

Popular in Java

  • Updating database using SQL prepared statement
  • getApplicationContext (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • addToBackStack (FragmentTransaction)
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • Option (scala)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now