{"action":"created","issue":{"url":"https://api.github.com/repos/NancyFx/Nancy/issues/1948","labels_url":"https://api.github.com/repos/NancyFx/Nancy/issues/1948/labels{/name}","comments_url":"https://api.github.com/repos/NancyFx/Nancy/issues/1948/comments","events_url":"https://api.github.com/repos/NancyFx/Nancy/issues/1948/events","html_url":"https://github.com/NancyFx/Nancy/issues/1948","id":82864547,"number":1948,"title":"How to handle render view exception to DefaultStatusCodeHandler","user":{"login":"lijunle","id":1296500,"avatar_url":"https://avatars.githubusercontent.com/u/1296500?v=3","gravatar_id":"","url":"https://api.github.com/users/lijunle","html_url":"https://github.com/lijunle","followers_url":"https://api.github.com/users/lijunle/followers","following_url":"https://api.github.com/users/lijunle/following{/other_user}","gists_url":"https://api.github.com/users/lijunle/gists{/gist_id}","starred_url":"https://api.github.com/users/lijunle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lijunle/subscriptions","organizations_url":"https://api.github.com/users/lijunle/orgs","repos_url":"https://api.github.com/users/lijunle/repos","events_url":"https://api.github.com/users/lijunle/events{/privacy}","received_events_url":"https://api.github.com/users/lijunle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-30T17:15:19Z","updated_at":"2015-05-30T19:08:08Z","closed_at":null,"body":"I am implementing a view engine. Inside the `RenderView` method, it might throw an exception. And I want to use the [DefaultStatusCodeHandler](https://github.com/NancyFx/Nancy/blob/master/src/Nancy/ErrorHandling/DefaultStatusCodeHandler.cs) to handle my exception.\r\n\r\n---\r\n\r\nI think there are two ways to throw the exception\r\n\r\n**First way** is to throw inside `RenderView` method\r\n\r\n```cs\r\npublic Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)\r\n{\r\n    var html = MethodMightThrowException();\r\n    return new HtmlResponse(contents: stream => AddHtmlToStream(html, stream));\r\n}\r\n```\r\n\r\nIn this case, the [caller](https://github.com/NancyFx/Nancy/blob/master/src/Nancy/ViewEngines/DefaultViewFactory.cs#L170) will eat up all exception and return an empty response.\r\n\r\n---\r\n\r\n**Second way** is to throw exception in HttpResponse content callback\r\n\r\n```cs\r\npublic Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext)\r\n{\r\n    return new HtmlResponse(contents: stream =>\r\n    {\r\n        var html = MethodMightThrowException();\r\n        AddHtmlToStream(html, stream);\r\n    });\r\n}\r\n```\r\n\r\nIn this case, the under hosting platform catch the exception will re-throw it to use. In my case, the ASP.NET catch it and show the famous classic yellow exception page.\r\n\r\n---\r\n\r\nBoth are not handling the exception to the DefaultStatusCodeHandler. **How can I do that?**"},"comment":{"url":"https://api.github.com/repos/NancyFx/Nancy/issues/comments/107076418","html_url":"https://github.com/NancyFx/Nancy/issues/1948#issuecomment-107076418","issue_url":"https://api.github.com/repos/NancyFx/Nancy/issues/1948","id":107076418,"user":{"login":"lijunle","id":1296500,"avatar_url":"https://avatars.githubusercontent.com/u/1296500?v=3","gravatar_id":"","url":"https://api.github.com/users/lijunle","html_url":"https://github.com/lijunle","followers_url":"https://api.github.com/users/lijunle/followers","following_url":"https://api.github.com/users/lijunle/following{/other_user}","gists_url":"https://api.github.com/users/lijunle/gists{/gist_id}","starred_url":"https://api.github.com/users/lijunle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lijunle/subscriptions","organizations_url":"https://api.github.com/users/lijunle/orgs","repos_url":"https://api.github.com/users/lijunle/repos","events_url":"https://api.github.com/users/lijunle/events{/privacy}","received_events_url":"https://api.github.com/users/lijunle/received_events","type":"User","site_admin":false},"created_at":"2015-05-30T19:08:08Z","updated_at":"2015-05-30T19:08:08Z","body":"/cc @grumpydev I saw you add MaterialisingResponse class in this PR #1504 . But I don't see any the pros from it. How do you think about this?\r\n\r\nBesides, I think the Razor view engine encountered some similar issues too (#1316, #1397)."}}