Recall & Review
beginner
What is the purpose of the
@Catch decorator in NestJS?The
@Catch decorator is used to define an exception filter that handles specific exceptions thrown in the application, allowing centralized error handling.Click to reveal answer
beginner
How do you specify which exceptions a filter should catch using the
@Catch decorator?You pass one or more exception classes as arguments to the
@Catch decorator. The filter will only handle those exceptions.Click to reveal answer
intermediate
What method must be implemented in a class decorated with <code>@Catch</code> to handle exceptions?The class must implement the <code>catch(exception: any, host: ArgumentsHost)</code> method, which contains the logic to handle the caught exception.Click to reveal answer
intermediate
Can the
@Catch decorator be used without arguments? What does that mean?Yes, if used without arguments, the filter will catch all exceptions, acting as a global catch-all error handler.
Click to reveal answer
intermediate
How do you apply a class with the <code>@Catch</code> decorator globally in a NestJS application?You provide the filter class in the <code>app.useGlobalFilters(new YourFilter())</code> method inside the main bootstrap function.Click to reveal answer
What does the
@Catch(HttpException) decorator do?✗ Incorrect
The decorator catches only exceptions of type HttpException.
Which method handles the exception inside a class decorated with
@Catch?✗ Incorrect
The
catch() method is required to handle exceptions.If you want to catch all exceptions, how do you use the
@Catch decorator?✗ Incorrect
Using
@Catch() without arguments catches all exceptions.How do you register a catch filter globally in NestJS?
✗ Incorrect
Global filters are registered with
app.useGlobalFilters().What argument does the
catch() method receive besides the exception?✗ Incorrect
The
catch() method receives the exception and an ArgumentsHost to access request/response.Explain how the
@Catch decorator works in NestJS and how you create a custom exception filter.Think about how you tell NestJS which errors to handle and where you write the handling code.
You got /4 concepts.
Describe the steps to apply a custom exception filter globally in a NestJS application.
Focus on how to make the filter work for the whole app, not just one controller.
You got /4 concepts.