{"id":237,"date":"2025-06-24T07:37:21","date_gmt":"2025-06-24T07:37:21","guid":{"rendered":"https:\/\/thetestdata.com\/blog\/?p=237"},"modified":"2025-07-16T10:25:42","modified_gmt":"2025-07-16T10:25:42","slug":"what-is-the-difference-between-a-checked-and-unchecked-exceptions","status":"publish","type":"post","link":"https:\/\/thetestdata.com\/blog\/what-is-the-difference-between-a-checked-and-unchecked-exceptions\/","title":{"rendered":"What is the difference between a checked and unchecked exceptions?"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">In Java, exceptions are divided into two main categories: <strong>checked<\/strong> and <strong>unchecked<\/strong> exceptions. Here&#8217;s a clear breakdown to help you grasp the difference:<\/h4>\n\n\n\n<p>\u2705 Checked Exceptions<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>These are <strong>checked at compile-time<\/strong>.<\/li>\n\n\n\n<li>Java forces you to either handle them using <code>try-catch<\/code> or declare them using <code>throws<\/code>.<\/li>\n\n\n\n<li>They represent <strong>recoverable conditions<\/strong>, like file not found, network issues, or database access errors.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1015\" height=\"115\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-11.png\" alt=\"\" class=\"wp-image-238\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-11.png 1015w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-11-300x34.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-11-768x87.png 768w\" sizes=\"auto, (max-width: 1015px) 100vw, 1015px\" \/><\/figure>\n\n\n\n<p><strong>Common checked exceptions:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>IOException<\/code><\/li>\n\n\n\n<li><code>SQLException<\/code><\/li>\n\n\n\n<li><code>FileNotFoundException<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u26a0\ufe0f Unchecked Exceptions<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>These are <strong>not checked at compile-time<\/strong>\u2014they occur at runtime.<\/li>\n\n\n\n<li>Java does <strong>not<\/strong> require you to handle them explicitly.<\/li>\n\n\n\n<li>They typically represent <strong>programming bugs<\/strong>, like logic errors or improper use of APIs.<\/li>\n<\/ul>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1009\" height=\"79\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-13.png\" alt=\"\" class=\"wp-image-240\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-13.png 1009w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-13-300x23.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-13-768x60.png 768w\" sizes=\"auto, (max-width: 1009px) 100vw, 1009px\" \/><\/figure>\n\n\n\n<p><strong>Common unchecked exceptions:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"934\" height=\"636\" src=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-12.png\" alt=\"\" class=\"wp-image-239\" srcset=\"https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-12.png 934w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-12-300x204.png 300w, https:\/\/thetestdata.com\/blog\/wp-content\/uploads\/2025\/06\/image-12-768x523.png 768w\" sizes=\"auto, (max-width: 934px) 100vw, 934px\" \/><\/figure>\n\n\n\n<p>\ud83e\udde0 Quick Summary:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>Checked Exceptions<\/th><th>Unchecked Exceptions<\/th><\/tr><\/thead><tbody><tr><td>Checked at compile-time?<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Requires handling?<\/td><td>Yes (<code>try-catch<\/code> or <code>throws<\/code>)<\/td><td>No handling required<\/td><\/tr><tr><td>Extends which class?<\/td><td><code>Exception<\/code> (but <em>not<\/em> <code>RuntimeException<\/code>)<\/td><td><code>RuntimeException<\/code><\/td><\/tr><tr><td>Examples<\/td><td><code>IOException<\/code>, <code>SQLException<\/code><\/td><td><code>NullPointerException<\/code>, <code>ArithmeticException<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Think of checked exceptions like seatbelts\u2014you <em>must<\/em> buckle up before driving (compiling). Unchecked exceptions are more like potholes\u2014Java won\u2019t stop you, but you might hit one if you&#8217;re not careful.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Understand the difference between checked and unchecked exceptions in Java. Learn how compile-time vs runtime errors affect exception handling strategies<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[17],"tags":[],"class_list":["post-237","post","type-post","status-publish","format-standard","hentry","category-java-interview-questions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":2,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/237\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}