From e7a540e717124187c68e6c0deb52aaafa5479109 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 23 Mar 2017 12:15:14 +1100 Subject: [PATCH] Proper Exception handling --- .../PublishedContent/PublishedContentType.cs | 2 +- .../XmlPublishedCache/XmlPublishedContent.cs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs index d05960b08f..63164cf271 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs @@ -179,7 +179,7 @@ namespace Umbraco.Core.Models.PublishedContent } if (contentType == null) - throw new Exception(string.Format("ContentTypeService failed to find a {0} type with alias \"{1}\".", + throw new InvalidOperationException(string.Format("ContentTypeService failed to find a {0} type with alias \"{1}\".", itemType.ToString().ToLower(), alias)); return new PublishedContentType(contentType); diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index 4e251d746e..1b0a428610 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -438,14 +438,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache contentType = getPublishedContentType(PublishedItemType.Content, docTypeAlias); } - catch (Exception e) + catch (InvalidOperationException e) { - if (e.TargetSite.Name == "CreatePublishedContentType") - { - content.Instance.RefreshContentFromDatabase(); - throw new Exception(string.Format("The content cache failed to find a content type with alias \"{0}\". This usually indicates that the content cache is corrupt; the content cache has been rebuilt in an attempt to self-fix the issue.", docTypeAlias)); - } - throw; + content.Instance.RefreshContentFromDatabase(); + + + throw new InvalidOperationException( + string.Format("{0}. This usually indicates that the content cache is corrupt; the content cache has been rebuilt in an attempt to self-fix the issue.", + //keep the original message but don't use this as an inner exception because we want the above message to be displayed, if we use the inner exception + //we can keep the stack trace but the header message will be the original message and the one we really want to display will be hidden below the fold. + e.Message)); } properties = new Dictionary(StringComparer.OrdinalIgnoreCase);