本文整理匯總了Java中com.google.inject.ProvisionException.getCause方法的典型用法代碼示例。如果您正苦於以下問題:Java ProvisionException.getCause方法的具體用法?Java ProvisionException.getCause怎麽用?Java ProvisionException.getCause使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.inject.ProvisionException
的用法示例。
在下文中一共展示了ProvisionException.getCause方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: unwrapException
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
public static <E extends Throwable> E unwrapException(Class<E> type, ProvisionException e) throws E {
if(e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else if(type.isInstance(e.getCause())) {
throw (E) e.getCause();
} else {
throw e;
}
}
示例2: requireThatExceptionIsThrown
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
@Test
public void requireThatExceptionIsThrown() {
try {
TestDriver.newInjectedApplicationInstanceWithoutOsgi(MyApplication.class);
fail();
} catch (ProvisionException e) {
Throwable t = e.getCause();
assertNotNull(t);
assertTrue(t instanceof ApplicationNotReadyException);
}
}
示例3: run
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
/**
* @param runtime runtime started by Bootique.
* @return the outcome of the command execution.
* @deprecated since 0.23. Previously this method existed to catch and process run exceptions, but it doesn't
* have wide enough scope for this, so exception processing was moved to {@link #exec()}.
*/
@Deprecated
private CommandOutcome run(BQRuntime runtime) {
try {
return runtime.getRunner().run();
}
// handle startup Guice exceptions
catch (ProvisionException e) {
// TODO: a dependency on JOPT OptionException shouldn't be here
return (e.getCause() instanceof OptionException) ? CommandOutcome.failed(1, e.getCause().getMessage())
: CommandOutcome.failed(1, e);
}
}
示例4: get
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
@Override
public String get() {
String canonicalUrl = super.get();
if (canonicalUrl != null) {
return canonicalUrl;
}
if (requestProvider != null) {
// No canonical URL configured? Maybe we can get a reasonable
// guess from the incoming HTTP request, if we are currently
// inside of an HTTP request scope.
//
final HttpServletRequest req;
try {
req = requestProvider.get();
} catch (ProvisionException noWeb) {
if (noWeb.getCause() instanceof OutOfScopeException) {
// We can't obtain the request as we are not inside of
// an HTTP request scope. Callers must handle null.
//
return null;
}
throw noWeb;
}
return CanonicalWebUrl.computeFromRequest(req);
}
// We have no way of guessing our HTTP url.
//
return null;
}
示例5: providing
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
/** @since 4.0 */
@SuppressWarnings("unchecked") // safe because this is the cxtor of the literal
public ScopedBindingBuilder providing(TypeLiteral<? extends T> cxtorLiteral) {
// Find a constructor that has @ThrowingInject.
Constructor<? extends T> cxtor =
CheckedProvideUtils.findThrowingConstructor(cxtorLiteral, binder);
final Provider<T> typeProvider;
final Key<? extends T> typeKey;
// If we found an injection point, then bind the cxtor to a unique key
if (cxtor != null) {
// Validate the exceptions are consistent with the CheckedProvider interface.
CheckedProvideUtils.validateExceptions(
binder, cxtorLiteral.getExceptionTypes(cxtor), exceptionTypes, interfaceType);
typeKey = Key.get(cxtorLiteral, UniqueAnnotations.create());
binder.bind(typeKey).toConstructor((Constructor) cxtor).in(Scopes.NO_SCOPE);
typeProvider = binder.getProvider((Key<T>) typeKey);
} else {
// never used, but need it assigned.
typeProvider = null;
typeKey = null;
}
// Create a CheckedProvider that calls our cxtor
CheckedProvider<T> checkedProvider =
new CheckedProviderWithDependencies<T>() {
@Override
public T get() throws Exception {
try {
return typeProvider.get();
} catch (ProvisionException pe) {
// Rethrow the provision cause as the actual exception
if (pe.getCause() instanceof Exception) {
throw (Exception) pe.getCause();
} else if (pe.getCause() instanceof Error) {
throw (Error) pe.getCause();
} else {
// If this failed because of multiple reasons (ie, more than
// one dependency failed due to scoping errors), then
// the ProvisionException won't have a cause, so we need
// to rethrow it as-is.
throw pe;
}
}
}
@Override
public Set<Dependency<?>> getDependencies() {
return ImmutableSet.<Dependency<?>>of(Dependency.get(typeKey));
}
};
Key<CheckedProvider<?>> targetKey =
Key.get(CHECKED_PROVIDER_TYPE, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(checkedProvider);
return toInternal(targetKey);
}
示例6: providing
import com.google.inject.ProvisionException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked") // safe because this is the cxtor of the literal
public ScopedBindingBuilder providing(TypeLiteral<? extends T> cxtorLiteral) {
// Find a constructor that has @ThrowingInject.
Constructor<? extends T> cxtor =
CheckedProvideUtils.findThrowingConstructor(cxtorLiteral, binder);
final Provider<T> typeProvider;
final Key<? extends T> typeKey;
// If we found an injection point, then bind the cxtor to a unique key
if (cxtor != null) {
// Validate the exceptions are consistent with the CheckedProvider interface.
CheckedProvideUtils.validateExceptions(
binder, cxtorLiteral.getExceptionTypes(cxtor), exceptionTypes, interfaceType);
typeKey = Key.get(cxtorLiteral, UniqueAnnotations.create());
binder.bind(typeKey).toConstructor((Constructor) cxtor).in(Scopes.NO_SCOPE);
typeProvider = binder.getProvider((Key<T>) typeKey);
} else {
// never used, but need it assigned.
typeProvider = null;
typeKey = null;
}
// Create a CheckedProvider that calls our cxtor
CheckedProvider<T> checkedProvider = new CheckedProviderWithDependencies<T>() {
@Override
public T get() throws Exception {
try {
return typeProvider.get();
} catch (ProvisionException pe) {
// Rethrow the provision cause as the actual exception
if (pe.getCause() instanceof Exception) {
throw (Exception) pe.getCause();
} else if (pe.getCause() instanceof Error) {
throw (Error) pe.getCause();
} else {
// If this failed because of multiple reasons (ie, more than
// one dependency failed due to scoping errors), then
// the ProvisionException won't have a cause, so we need
// to rethrow it as-is.
throw pe;
}
}
}
@Override
public Set<Dependency<?>> getDependencies() {
return ImmutableSet.<Dependency<?>>of(Dependency.get(typeKey));
}
};
Key<CheckedProvider> targetKey = Key.get(CheckedProvider.class, UniqueAnnotations.create());
binder.bind(targetKey).toInstance(checkedProvider);
return toInternal(targetKey);
}