#Exception handling in spring

1 messages · Page 1 of 1 (latest)

crisp elk
#

i dont understand why we need global exception class and why we use builder pattern. what r the main topics i need to understand when i use exception handling in spring
because i be watching these yt tutorials i see them do stuff but i dont understand why

hidden kestrelBOT
#

<@&1004656351647117403> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
I dont understand why we need global exception class and why we use builder pattern. what r the main topics i need to understand when i use exception handling in spring because i be watching these yt tutorials i see them do stuff but i dont understand why

In Spring, a global exception class is used to centralize exception handling logic and make it easier to manage and customize error responses. The builder pattern is often used to create complex exception objects with different attributes.

When using exception handling in Spring, you need to understand the following main topics:

  1. Exception hierarchies and types in Spring
  2. Custom exception classes and handling
  3. Exception resolution strategies like @ExceptionHandler and @ControllerAdvice

Useful links:

tidal olive
#

that question feels a bit broad. u mention multiple vague topics and im not sure yet how it connects in ur mind.

could u potentially just share an example of what ur looking at? then its clear and we can help explaining 🙂

crisp elk
#

i see people use specific approaches to use exception handling like making a global exception handling class and using something called build pattern and stuff like that i dont understand why they do it instead of the traditional way

#

also i dont know what approaches i need to learn in exception handling when using spring boot

tidal olive
#

mind sharing an example or sth

mighty patio
#

yeah an example would be helpful

#

exception handling in what sense btw

#

you mean @ExceptionHandler methods?

tidal olive
#

exception handling in spring isn't really different to non-spring.
u use normal try-catch.
the other options are for a level above that, when u want to define for example global handlers for exceptions that werent handled. in order to for example perform shutdown procedures or logging

#

similar to shutdown-hooks in "normal java"

#

doing it through the annotations is necessary in spring bc u dont control the general control flow

#

spring deals with ur services and calls their methods, not u

#

so if u want exception handling on their "global" level, u need the annotations

#

simple bc u dont have a real alternative