{"id":738,"date":"2010-08-07T00:18:51","date_gmt":"2010-08-06T18:48:51","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=738"},"modified":"2010-08-07T00:18:51","modified_gmt":"2010-08-06T18:48:51","slug":"checked-unchecked-exception","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/checked-unchecked-exception\/","title":{"rendered":"Checked and Unchecked Exception"},"content":{"rendered":"<p>There are two types of exception available in java:<\/p>\n<ol>\n<li>Checked exception<\/li>\n<li>Unchecked exception<\/li>\n<\/ol>\n<p><strong>Checked exception:<\/strong><\/p>\n<ol>\n<li>Checked exception represents the invalid condition is program and must be declared by using keyword <strong>throws <\/strong>in method.<\/li>\n<li>checked exception extends <strong><a title=\"Exception API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/Exception.html\" target=\"_blank\">java.lang.Exception<\/a><\/strong> class.<\/li>\n<li><a title=\"Oracle IOException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/io\/IOException.html\" target=\"_blank\">IOException<\/a>, <a title=\"Oracle JAVA ClassNotFoundException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/ClassNotFoundException.html\" target=\"_blank\">ClassNotFoundException<\/a>, <a title=\"SAXException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/org\/xml\/sax\/SAXException.html\" target=\"_blank\">SAXException <\/a>are the well known examples of checked exception.<\/li>\n<\/ol>\n<p>example:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic void setDate() throws ShivaSoftException\n{\n   if(dateOfBirth &lt; todaysDate)\n   {\n        throw new ShivaSoftException(&quot;Date of birth cannot be in future&quot;);\n   }\n}\n<\/pre>\n<p>checked exception forces the calling method to be <strong>enclosed in try catch block<\/strong>.<\/p>\n<p><strong>Unchecked Exception:<\/strong><\/p>\n<ol>\n<li>Unchecked exception represents the defect in programming logic and occurs at runtime. it does not forces the code to be enclosed in try catch block.<\/li>\n<li>Unchecked Exception extends<a title=\"RunTimeException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/RuntimeException.html\" target=\"_blank\"> <strong>java.lang.RuntimeException<\/strong><\/a> class.<\/li>\n<li><a title=\"Arithmatic Exception\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/ArithmeticException.html\" target=\"_blank\">ArithmaticException<\/a>, <a title=\"NullPointerException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/NullPointerException.html\" target=\"_blank\">NullPointerException<\/a>,\u00a0<a title=\"IndexOutOfBoundsException API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/IndexOutOfBoundsException.html\" target=\"_blank\">IndexOutOfBoundsException <\/a>are well known examples of Unchecked Exception.<\/li>\n<\/ol>\n<p>example:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic void errorMethod()\n{\n   System.out.println(10\/0);\n}\n<\/pre>\n<p>The above method will give the <strong>ArithematicException <\/strong>at runtime but did not force to be enclosed during compile time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explains the concept of checked exception and unchecked exception in JAVA.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[94],"class_list":["post-738","post","type-post","status-publish","format-standard","hentry","category-java","tag-exception"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2009,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/exception-and-error-handling-framework-in-java\/","url_meta":{"origin":738,"position":0},"title":"Exception and Error handling framework in Java","author":"Jitendra","date":"April 15, 2011","format":false,"excerpt":"Explain the concept of Exception and Error handling framework in JAVA.","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"JAVA Exception Framework","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/JAVA-Exception-Framework.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1638,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/exception-chaining\/","url_meta":{"origin":738,"position":1},"title":"Exception chaining in Java","author":"Jitendra","date":"March 14, 2011","format":false,"excerpt":"Concept of Exception chaining with example in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"Exception Chaining","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Exception-Chaining.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2017,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-j2ee-interview-questions-1\/","url_meta":{"origin":738,"position":2},"title":"Java &#8211; J2EE Interview Questions &#8211; 1","author":"Jitendra","date":"April 15, 2011","format":false,"excerpt":"JAVA - J2EE Interview Questions - 1, JAVA - J2EE Interview Questions - 1,custom tag JSP, Externalization , serialVersionUID, difference between interface and abstract class, iterate HashMap","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":936,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jdbc-example-with-microsoft-access-in-swing\/","url_meta":{"origin":738,"position":3},"title":"JDBC Example with Microsoft Access in Swing, Next and Previous navigation","author":"Jitendra","date":"August 31, 2010","format":false,"excerpt":"JDBC - Java Database Connectivity example in Swing","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1820,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-threading-executor-framework-and-callable-interface\/","url_meta":{"origin":738,"position":4},"title":"Java Threading &#8211; Executor Framework and Callable Interface","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Java Threading - Executor Framework and Callable Interface with example","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1029,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/logging-made-easy-in-net-log-4-net\/","url_meta":{"origin":738,"position":5},"title":"Logging made easy in .NET &#8211; log 4 net","author":"Jitendra","date":"September 30, 2010","format":false,"excerpt":"How to use the log 4 net in .Net application. Example, demonstration and sourcecode","rel":"","context":"In &quot;c#&quot;","block_context":{"text":"c#","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/csharp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=738"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/738\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}