while studying spring I stumbled over this question. Java supports both checked and unchecked exceptions. Language-agnostic design guidelines seems to favour unchecked exceptions. This question is why using an inversion of control-container like Spring implies that I should only use unchecked exceptions.
Why does spring prefer unchecked exceptions?
3.9k Views Asked by Jesper At
1
There are 1 best solutions below
Related Questions in SPRING
- HTTPS configuration in Spring Boot, server returning timeout
- Multi Tenancy in Spring - Partitioned Data Approach
- How to create beans of the same class for multiple template parameters in Spring
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Springboot: How to get an entity optional property and check null?
- How do I propagate the current SecurityContext to my @RabbitListener in Spring Boot?
- Spring's XML based bean configuration for Object Mapper's Case Insensitive property
- Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. I'm using Postgresql
- springboot class org.hibernate.mapping.Bag cannot be cast to class org.hibernate.mapping.SimpleValue
- Issue while deploying JDK 17 and Spring 6 application in Tomcat 10.1.20
- Spring JPA Data Auditing - How to design it?
- Springframework test: Async not started
- Error: Cannot invoke "jakarta.servlet.http.HttpSession.getAttribute(String)" because "session" is null
- How does spring-retry determine which methods to retry when @Retryable is placed at the class level?
- problem with edge server registration in Eureka
Related Questions in EXCEPTION
- What should i use Exceptions or Monads for handle if service occur a problem?
- Python Requests: Handling Exceptions and Ensuring Server Response
- What is a better way to allow no user input while also preventing non-number inputs
- New error on random number assigned to local variable , Rails
- spring error exception with oauth2 and securityconfig
- Exception thrown: 'System.InvalidOperationException' in Microsoft.Data.SqlClient.dll
- How to fix this Row nested in Column exception issue in Flutter?
- GDI - Why the printing StartPage() function works in 32 bit but raises an exception in 64 bit?
- Handling Invalid Credential or Login error Exception in Python for Network Devices
- Execution failed for task ':app:compileFlutterBuildDebug'. > Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1Error:
- .NET 6 Custom Nuget package referencing other packages - Do I have to include the other packages myself?
- How to prevent Unity from catching and ignoring ALL exceptions
- My Google Apps Script renames all files in a folder from data in a spreadsheet. Can someone explain why it returns an exception error?
- Python (pylint): Catching general exceptions in validation procedures
- Need a simple example how to catch a data type error en C++
Related Questions in DESIGN-GUIDELINES
- iOS header design guidelines
- When is it acceptable to declare an instance attribute outside "__init__()"?
- Combined Buy/Restore button for non-consumable IAP in iOS?
- Statuscode guidelines when acting as a middle-man
- What is the good way of storing software version for python CLI ? (<app> --version)
- Layout: center image inside center panel. Using percent units
- Better style inside a vue.js app or outsource to the site embedding it?
- Why have public constructors in custom exceptions
- Integrating Google pay buttons and Apple pay buttons into react-native application
- Are Result objects the cleaner way to handle failure, than exceptions?
- How to distinguish unexpected (boneheaded) exceptions from expected (exogenous) ones?
- Can I package entire iOS app as a Framework?
- Container view for a screen with multiple tableviews in iOS?
- What layout is better for a UI with two card cells per row?
- What is the standard practice for designing REST API if it is being used for inserting / updating a list of records
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The question "why using an inversion of control-container like Spring implies that I should only use unchecked exceptions" is a bit strange. And I am not sure that using IoC implies you should use unchecked exceptions. Checked vs unchecked is in the end matter of context and opinion.
My view on this:
Exceptions can be categorized in checked and unchecked exceptions. That simply means that some exceptions, the checked ones, require us to specify at compile time how the application will behave in case the exception occurs. The unchecked exceptions do not mandate compile time handling from us. To create such exceptions, you extend the RuntimeException class which is a direct subclass of Exception. An old and common guideline when it comes to checked vs unchecked is that runtime exceptions are used to signal situations which the application usually cannot anticipate or recover from, while checked exceptions are situations that a well-written application should anticipate and recover from.
I am an advocate of only using runtime exceptions. And if I use a library that has a method with a checked exception, I create a wrapper method that turns it into a runtime. Why not checked exceptions then? Uncle Bob, in his “Clean Code” book, argues that they break the Open/Closed principle, since a change in the signature with a new throws declaration could have effects in many levels of our program calling the method.
I have written a post about dealing with exceptions, you could check it out if interested: https://dzone.com/articles/how-to-deal-with-exceptions