public void HandleException(object errorSource, Exception e) { bool handled = false; for (int i = 0; (i < ErrorHandlers.Count); ++i) { var errorHandler = ErrorHandlers[i]; try { GuardedOperations.LastHandledException = e; GuardedOperations.LastHandleExceptionStackTrace = e.StackTrace; errorHandler.HandleError(errorSource, e); handled = true; } catch (Exception doubleFaultException) { // TODO: What is the right behavior here? GuardedOperations.Fail(doubleFaultException.ToString()); } } if (!handled) { // TODO: What is the right behavior here? GuardedOperations.Fail(e.ToString()); if (GuardedOperations.ReThrowIfNoHandlers) { throw new Exception("Unhandled exception.", e); } } }
public void LogException(object errorSource, Exception e) { var logged = false; for (int i = 0; (i < ErrorHandlers.Count); ++i) { var errorHandler = ErrorHandlers[i] as IExtensionErrorHandler2; if (errorHandler != null) { try { GuardedOperations.LastHandledException = e; GuardedOperations.LastHandleExceptionStackTrace = e.StackTrace; errorHandler.LogError(errorSource, e); logged = true; } catch (Exception doubleFaultException) { // TODO: What is the right behavior here? GuardedOperations.Fail(doubleFaultException.ToString()); } } } if (!logged) { Debug.WriteLine(e.Message); } }
/// <summary> /// Given a list of extensions that provide text view roles and content types, return the /// instantiated extension which best matches the given content type and matches at least one of the roles. /// </summary> public static TExtensionInstance InvokeBestMatchingFactory <TExtensionInstance, TExtensionFactory, TMetadataView> (IEnumerable <Lazy <TExtensionFactory, TMetadataView> > providerHandles, IContentType dataContentType, ITextViewRoleSet viewRoles, Func <TExtensionFactory, TExtensionInstance> getter, IContentTypeRegistryService contentTypeRegistryService, GuardedOperations guardedOperations, object errorSource) where TMetadataView : IContentTypeAndTextViewRoleMetadata // both content type and text view role are required where TExtensionFactory : class where TExtensionInstance : class { var roleMatchingProviderHandles = SelectMatchingExtensions(providerHandles, viewRoles); return(guardedOperations.InvokeBestMatchingFactory(roleMatchingProviderHandles, dataContentType, getter, contentTypeRegistryService, errorSource)); }