Here is a cshtml RazorSharp page that shows how to catch an exception (note the multiple mixes of code and HTML)
Here is what it looks like when rendered (note the 1 line stack trace):
After resetting the Razor Pages compilation cache, here is another screenshot of the execution (note the different value in the StackTrace):