I was trying to return an error to the call to the controller as advised in This link so that client can take appropriate action. The controller is called by javascript via
The thing that worked for me (and that I took from another stackoverflow response), is to set the flag:
Response.TrySkipIisCustomErrors = true;