the best way for throwing and managing exception java - spring?

50 views Asked by At

I want to ask if someone can help me that what is the best way for managing exception like if we add some user and want to throw for ex. UserNotExist should we extend with Exception or Runtime exception , does anyone have any material that can help me .

1

There are 1 answers

0
DimaSan On

As exceptions inherited from Exception class are checked exceptions, and exceptions inherited from RuntimeException class are unchecked exceptions, your question may be viewed, as what kind of exceptions to use.

As recommended in Oracle official documentation:

If a client can reasonably be expected to recover from an exception, make it a checked exception.
If a client cannot do anything to recover from the exception, make it an unchecked exception.