private Exception ExecuteHandlerChain(Exception ex, Guid handlingInstanceID) { string lastHandlerName = String.Empty; Exception originalException = ex; try { foreach (IExceptionHandler handler in handlers) { lastHandlerName = handler.GetType().Name; ex = handler.HandleException(ex, handlingInstanceID); instrumentationProvider.FireExceptionHandlerExecutedEvent(); } } catch (Exception handlingException) { instrumentationProvider.FireExceptionHandlingErrorOccurred( ExceptionUtility.FormatExceptionHandlingExceptionMessage( policyName, new ExceptionHandlingException(string.Format(CultureInfo.CurrentCulture, Resources.UnableToHandleException, lastHandlerName), handlingException), ex, originalException)); throw new ExceptionHandlingException(string.Format(CultureInfo.CurrentCulture, Resources.UnableToHandleException, lastHandlerName)); } return(ex); }
private static ExceptionPolicyImpl GetExceptionPolicy(Exception exception, string policyName) { try { return(EnterpriseLibraryContainer.Current.GetInstance <ExceptionPolicyImpl>(policyName)); } catch (ActivationException configurationException) { try { DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryContainer.Current.GetInstance <DefaultExceptionHandlingEventLogger>(); logger.LogConfigurationError(configurationException, policyName); } catch { } throw; } catch (Exception ex) { try { string exceptionMessage = ExceptionUtility.FormatExceptionHandlingExceptionMessage(policyName, ex, null, exception); DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryContainer.Current.GetInstance <DefaultExceptionHandlingEventLogger>(); logger.LogInternalError(policyName, exceptionMessage); } catch { } throw new ExceptionHandlingException(ex.Message, ex); } }
private static ExceptionPolicyImpl GetExceptionPolicy(Exception exception, string policyName, ExceptionPolicyFactory factory) { try { return(factory.Create(policyName)); } catch (ConfigurationErrorsException configurationException) { try { DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>(); logger.LogConfigurationError(configurationException, policyName); } catch { } throw; } catch (Exception ex) { try { string exceptionMessage = ExceptionUtility.FormatExceptionHandlingExceptionMessage(policyName, ex, null, exception); DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>(); logger.LogInternalError(policyName, exceptionMessage); } catch { } throw new ExceptionHandlingException(ex.Message, ex); } }
/// <devdoc> /// Rethrows the given exception. Placed in a seperate method for /// easier viewing in the stack trace. /// </devdoc> private Exception IntentionalRethrow(Exception chainException, Exception originalException) { if (chainException != null) { throw chainException; } Exception wrappedException = new ExceptionHandlingException(Resources.ExceptionNullException); instrumentationProvider.FireExceptionHandlingErrorOccurred( ExceptionUtility.FormatExceptionHandlingExceptionMessage(policyName, wrappedException, chainException, originalException)); return(wrappedException); }