CodePark/ questions / Exception filters
START PRACTICINGPRACTICE
Backend question · NestJS › Exception filters

A route has a method-level filter @Catch(HttpException), the controller has @Catch(NotFoundException), and a global @Catch() filter exists. The handler throws NotFoundException. Which filter handles it?

The method-level HttpException filter

The method-level HttpException filter handles it. Nest checks filters in this order: route, then controller, then global. It uses the first filter whose @Catch() matches. NotFoundException extends HttpException, so the method-level filter matches. No other filter runs.

"The controller-level
NotFoundException filter, because it is the most specific match" is wrong. Nest picks by binding level, not by which exception class is most specific. "All three run in sequence" is also wrong: only one filter runs.