René's URL Explorer Experiment


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/

direct link

Domain: thecodeforge.io


Hey, it has json ld scripts:
{
  "@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:typewebsite
og:imagehttps://thecodeforge.io/assets/og-image.png
og:image:width1200
og:image:height630

Links:

TheCodeForge https://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Buy me a coffee https://ko-fi.com/thecodeforge
1Exception Handling in Javahttps://thecodeforge.io/java/exception-handling-java/
2try-catch-finally in Javahttps://thecodeforge.io/java/try-catch-finally-java/
3Custom Exceptions in Javahttps://thecodeforge.io/java/custom-exceptions-java/
4throws and throw in Javahttps://thecodeforge.io/java/throws-throw-java/
5Checked vs Unchecked Exceptionshttps://thecodeforge.io/java/checked-unchecked-exceptions-java/
6Multi-catch and Finally Blockhttps://thecodeforge.io/java/multi-catch-finally-java/
7Java NullPointerException Fixhttps://thecodeforge.io/java/java-nullpointerexception/
8Java ClassNotFoundException Fixhttps://thecodeforge.io/java/java-classnotfoundexception/
9Java SSLHandshakeException Fixhttps://thecodeforge.io/java/java-sslhandshakeexception/
10Java IllegalArgumentException Fixhttps://thecodeforge.io/java/java-illegalargumentexception/
11Java NumberFormatException Fixhttps://thecodeforge.io/java/java-numberformatexception/
12Java NoSuchElementException Fixhttps://thecodeforge.io/java/java-nosuchelementexception/
13Java ArrayIndexOutOfBounds Fixhttps://thecodeforge.io/java/java-arrayindexoutofboundsexception/
14Java IllegalStateException Fixhttps://thecodeforge.io/java/java-illegalstateexception/
15Java ClassCastException Fixhttps://thecodeforge.io/java/java-classcastexception/
16Java InvocationTargetException Fixhttps://thecodeforge.io/java/java-invocationtargetexception/
17Java NoSuchMethodError Fixhttps://thecodeforge.io/java/java-nosuchmethoderror/
18Java ConcurrentModification Fixhttps://thecodeforge.io/java/java-concurrentmodificationexception/
19Java ArithmeticException Fixhttps://thecodeforge.io/java/java-arithmeticexception/
20Java Could Not Find Main Class Fixhttps://thecodeforge.io/java/java-could-not-find-or-load-main-class/
← Back to Java track https://thecodeforge.io/java/
Homehttps://thecodeforge.io/
Javahttps://thecodeforge.io/java/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
 ● Production Incidenthttps://thecodeforge.io/java/checked-unchecked-exceptions-java/#v2-production-incident
 🔎 Debug Guidehttps://thecodeforge.io/java/checked-unchecked-exceptions-java/#v2-debug-guide
 ⚙ Triage Commandshttps://thecodeforge.io/java/checked-unchecked-exceptions-java/#v2-triage-commands
designhttps://thecodeforge.io/java/design-patterns-java/
inheritancehttps://thecodeforge.io/java/inheritance-java/
custom exceptionshttps://thecodeforge.io/java/custom-exceptions-java/
arrayhttps://thecodeforge.io/dsa/array-data-structure/
machinehttps://thecodeforge.io/ml-ai/introduction-machine-learning/
stackhttps://thecodeforge.io/dsa/stack-data-structure/
abstractionhttps://thecodeforge.io/java/abstraction-java/
Spring Boothttps://thecodeforge.io/java/spring-boot-docker/
reacthttps://thecodeforge.io/interview/react-interview-questions/
control flowhttps://thecodeforge.io/c-cpp/control-flow-c/
→Java Exception Handling Explained — try, catch, finally and Real-World PatternsMaster Java exception handling with real-world patterns, checked vs unchecked exceptions, custom exceptions, and the gothttps://thecodeforge.io/java/exception-handling-java/
→throws in Java — The Silent Data Loss Anti-PatternException in main() with throws — SQLException from timeout goes to stderr, not logs, causing silent failures. Catch andhttps://thecodeforge.io/java/throws-throw-java/
→Multi-catch Java — Finally Return Trap Silent FailureA `return "SUCCESS";` in finally silently failed payments. Debug this Java multi-catch trap and fix with try-with-resourhttps://thecodeforge.io/java/multi-catch-finally-java/
→Java try-catch-finally — The Silent Connection Leak PatternConnection pool leaks over 4-6 hours until exhaustion because finally block discards original exception. Use try-with-rehttps://thecodeforge.io/java/try-catch-finally-java/
→C# Exception Handling Explained — try, catch, finally and Real PatternsMaster C# exception handling with try, catch, finally, and custom exceptions. Learn real-world patterns, common mistakeshttps://thecodeforge.io/csharp/exception-handling-csharp/
Find Middle of Linked ListBeginnerhttps://thecodeforge.io/dsa/find-middle-linked-list/
Follow https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
←Previousthrows and throw in Javahttps://thecodeforge.io/java/throws-throw-java/
NextMulti-catch and Finally Block→https://thecodeforge.io/java/multi-catch-finally-java/
LinkedIn https://www.linkedin.com/in/thecodeforge-io-a0676b3b5/
Facebook https://www.facebook.com/profile.php?id=61583020033815
YouTube https://www.youtube.com/channel/UCMar7CF2EmCF1I2tw1tNVuQ
Javahttps://thecodeforge.io/java/
Pythonhttps://thecodeforge.io/python/
C / C++https://thecodeforge.io/c-cpp/
JavaScripthttps://thecodeforge.io/javascript/
DSAhttps://thecodeforge.io/dsa/
Databasehttps://thecodeforge.io/database/
System Designhttps://thecodeforge.io/system-design/
DevOpshttps://thecodeforge.io/devops/
C# / .NEThttps://thecodeforge.io/csharp/
PHPhttps://thecodeforge.io/php/
ML / AIhttps://thecodeforge.io/ml-ai/
Interviewhttps://thecodeforge.io/interview/
CS Fundamentalshttps://thecodeforge.io/cs-fundamentals/
Rusthttps://thecodeforge.io/rust/
Toolshttps://thecodeforge.io/tools/
Cheatsheetshttps://thecodeforge.io/cheatsheets/
Mobilehttps://thecodeforge.io/mobile/
Data Analyticshttps://thecodeforge.io/data-analytics/
Securityhttps://thecodeforge.io/security/
Frontendhttps://thecodeforge.io/frontend/
Data Engineeringhttps://thecodeforge.io/data-engineering/
Testinghttps://thecodeforge.io/testing/
Cloudhttps://thecodeforge.io/cloud/
Observabilityhttps://thecodeforge.io/observability/
Web Platformhttps://thecodeforge.io/web-platform/
🧯 Errors Explainedhttps://thecodeforge.io/errors/
⚒ Blueprintshttps://thecodeforge.io/blueprints/
⌨ Practicehttps://thecodeforge.io/practice/
Interview Prephttps://thecodeforge.io/interview/
DSA Problemshttps://thecodeforge.io/dsa/
Developer Toolshttps://thecodeforge.io/tools/
Cheat Sheetshttps://thecodeforge.io/cheatsheets/
Abouthttps://thecodeforge.io/about/
Sitemaphttps://thecodeforge.io/sitemap.xml
Privacyhttps://thecodeforge.io/privacy.html

Viewport: width=device-width, initial-scale=1.0

Robots: max-image-preview:large


URLs of crawlers that visited me.