score:2

Accepted answer

From the documentation

You can customize how Web API handles exceptions by writing an exception filter. An exception filter is executed when a controller method throws any unhandled exception[...]

The problem is that if you return an IEnumerable<T> from your WebAPI method, the error will occur during serialization, when the IEnumerable<T> is iterated. This is the standard behavior of Select (and most other query operators) it only call the method passed to it upon iteration (MakeFooFromBar in this case), so the exception will not be thrown when you invoke Select but much later.

You could add a .ToList to cause the exception to occur inside your method.


Related Query

More Query from same tag