Display 404 page from razor code

I have a template which displays a page list items, and uses a modified version of the paging script coming with Umbraco.

The script works by retrieving the current page to display from a parameter in the url, typically ?page=xx

It is possible to call this url with invalid page numbers, and I'd like to return the 404 page for those requests.

How can I display the 404 page from within razor code? I don't want to redirect the user, just display the 404 page.

I tried

throw new HttpException(404, "Page not found");

but this results in macro errors.


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/33761-display-404-page-from-razor-code