handledThrowables.get().clear();
List<ObserverMethod> observers = resolveObservers(event.getClass());
List<ObserverMethod> interceptorObservers = resolveInterceptorObservers(event.getClass());
ApplicationContext context = (ApplicationContext)getScopedContext(ApplicationScoped.class);
// We need to know if we were to the one to Activate it to avoid:
// * nested ApplicationContexts
// * ending the scope to soon (to low in the stack)
boolean activatedApplicationContext = false;
try
{
if(!context.isActive()) {
context.activate();
activatedApplicationContext = true;
}
new EventContextImpl<T>(this, interceptorObservers, observers, nonManagedObserver, event).proceed();
}
catch (Exception e)
{
Throwable fireException = e;
if(fireException instanceof InvocationException)
{
fireException = fireException.getCause();
}
if(handledThrowables.get().contains(fireException.getClass()))
{
UncheckedThrow.throwUnchecked(fireException);
}
else
{
fireException(fireException);
}
}
finally
{
debug(event, false);
if(activatedApplicationContext && context.isActive()) {
context.deactivate();
}
}
}