Title: Java Exceptions — Why Empty Catch Blocks Cause Duplicate
Open Graph Title: Java Exceptions — Why Empty Catch Blocks Cause Duplicate
Description: Empty catch blocks caused duplicate charges when IOException was swallowed. See the wrapping patterns that prevent silent production failures.
Open Graph Description: Empty catch blocks caused duplicate charges when IOException was swallowed. See the wrapping patterns that prevent silent production failures.
Opengraph URL: https://thecodeforge.io/java/checked-unchecked-exceptions-java/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/java/checked-unchecked-exceptions-java/"
},
"headline": "Java Exceptions — Why Empty Catch Blocks Cause Duplicate Charges",
"description": "Empty catch blocks caused duplicate charges when IOException was swallowed. See the wrapping patterns that prevent silent production failures.",
"keywords": "Java Exceptions — Why Empty Catch Blocks Cause Duplicate Charges, Java, Intermediate, Exception Handling, Empty catch blocks caused duplicate charges when IOException was swallowed. See the wrapping patterns that prevent silent production failures.",
"proficiencyLevel": "Intermediate",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-05T00:00:00+00:00",
"dateModified": "2026-08-30T00:00:00+00:00",
"url": "https://thecodeforge.io/java/checked-unchecked-exceptions-java/",
"inLanguage": "en",
"educationalLevel": "Intermediate",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
{"@type": "ListItem", "position": 3, "name": "Java Exceptions — Why Empty Catch Blocks Cause Duplicate Charges", "item": "https://thecodeforge.io/java/checked-unchecked-exceptions-java/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "Can you convert a checked exception to an unchecked exception in Java?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes — and this is a common, recommended pattern. Catch the checked exception and rethrow it wrapped inside a class that extends RuntimeException, passing the original as the cause constructor argument. This is exactly what Spring does with SQLException → DataAccessException. The key is to always pass the original exception as the cause so the full stack trace is preserved in your logs."
}
},
{
"@type": "Question",
"name": "Should I use checked or unchecked exceptions for my custom business exceptions?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Use checked exceptions when the failure is environmental and the direct caller can take a meaningful alternative action — for example, a payment gateway being unreachable. Use unchecked exceptions when the failure represents a programming contract violation — for example, passing a null order ID to a method that explicitly requires one. When in doubt, modern Java practice (and frameworks like Spring) leans toward unchecked to avoid polluting method signatures."
}
},
{
"@type": "Question",
"name": "Does catching Exception catch both checked and unchecked exceptions?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes — at runtime, catching Exception catches everything except Errors, because RuntimeException is a subclass of Exception. This is precisely why catching Exception broadly is dangerous: you'll accidentally swallow NullPointerExceptions and other programming bugs alongside the specific checked exception you intended to handle. Always catch the most specific exception type you can meaningfully act on."
}
},
{
"@type": "Question",
"name": "Why do most Spring framework exceptions extend RuntimeException?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Because Spring's designers recognised that at the point where infrastructure failures occur (database, network, file I/O), the immediate caller — usually a controller or service — cannot take meaningful recovery action. Forcing every caller to catch and handle SQLException would create massive boilerplate with no benefit. Using unchecked exceptions allows the framework to provide a global exception handler (@ControllerAdvice) that centralises error handling, keeping business logic clean."
}
},
{
"@type": "Question",
"name": "What is the difference between throws and throw in relation to checked exceptions?",
"acceptedAnswer": {
"@type": "Answer",
"text": "'throws' is used in a method signature to declare that the method might throw a checked exception. It is mandatory for checked exceptions that are not caught inside the method. 'throw' is the actual statement that throws an exception instance. For checked exceptions, you must either catch them (try-catch) or declare them (throws). For unchecked exceptions, neither is required, though you may still use throws for documentation purposes (compiler ignores it)."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large