User-745470448 posted
I'm trying (hoping?) to use exception filtering in a ASP.NET Web Pages / Razor website. I'm using C# 7 with Microsoft.AspNet.Razor 3.27 and Microsoft.AspNet.WebPages 3.2.7, but I'm still getting errors when trying to use the keyword 'when' in a try catch
block, like:
try
{
// do something
}
catch (Exception ex) when (Log("log an error"))
{
}
The error is:
Error Expected a "{" but found a "when". Block statements must be enclosed in "{" and "}". You cannot use single-statement control-flow statements in CSHTML pages. For example, the following is not allowed:
@if(isLoggedIn)
<p>Hello, @user</p>
Instead, wrap the contents of the block in "{}":
@if(isLoggedIn) {
<p>Hello, @user</p>
}
Does Web Pages Razor 3.2.7 just not support exception filtering? It looks like it was added to the Razor that's part of .NET Core Razor back in 2015.