Bird
0
0

Why should custom pipes throw exceptions instead of returning error values?

hard📝 Conceptual Q10 of 15
NestJS - Pipes

Why should custom pipes throw exceptions instead of returning error values?

AExceptions are ignored by NestJS and do not affect flow
BThrowing exceptions stops request processing and sends proper HTTP error responses
CReturning error values is faster and preferred
DReturning error values automatically retries the request
Step-by-Step Solution
Solution:
  1. Step 1: Understand NestJS error handling

    Throwing exceptions interrupts the request lifecycle and triggers HTTP error responses.
  2. Step 2: Compare with returning error values

    Returning error values does not stop processing and can cause unexpected behavior.
  3. Final Answer:

    Throwing exceptions stops request processing and sends proper HTTP error responses -> Option B
  4. Quick Check:

    Throw exceptions for validation errors in pipes [OK]
Quick Trick: Throw exceptions to stop invalid requests cleanly [OK]
Common Mistakes:
  • Returning error values instead of throwing
  • Expecting exceptions to be ignored
  • Thinking errors auto-retry requests

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes