{"id":2009,"date":"2011-04-15T10:57:59","date_gmt":"2011-04-15T05:27:59","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2009"},"modified":"2011-04-15T10:57:59","modified_gmt":"2011-04-15T05:27:59","slug":"exception-and-error-handling-framework-in-java","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/exception-and-error-handling-framework-in-java\/","title":{"rendered":"Exception and Error handling framework in Java"},"content":{"rendered":"<p>In Java, the base class of all the Exceptions are &#8220;<a title=\"Throwable class\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/Throwable.html\">java.lang.Throwable<\/a>&#8220;. This class has two subclasses &#8211; &#8220;<a title=\"Java Error\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/Error.html\" target=\"_blank\">Error<\/a>&#8221; and &#8220;<a title=\"Exception API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/Exception.html\" target=\"_blank\">Exception<\/a>&#8220;.<\/p>\n<figure id=\"attachment_2013\" aria-describedby=\"caption-attachment-2013\" style=\"width: 474px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/JAVA-Exception-Framework.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2013 \" title=\"JAVA Exception Framework\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/JAVA-Exception-Framework.jpg?resize=474%2C257&#038;ssl=1\" alt=\"JAVA Exception Framework\" width=\"474\" height=\"257\" \/><\/a><figcaption id=\"caption-attachment-2013\" class=\"wp-caption-text\">JAVA Exception Framework<\/figcaption><\/figure>\n<p><strong>java.lang.Error<\/strong> indicates serious problems that a reasonable<strong> application should not try to catch<\/strong>. Most such errors are abnormal conditions.<br \/>\nExamples :<a title=\"ThreadDeath API\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/ThreadDeath.html\" target=\"_blank\"> java.lang.ThreadDeath<\/a> and<a title=\"VirtualMachineError\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/VirtualMachineError.html\" target=\"_blank\"> java.lang.VirtualMachineError<\/a><!--more--><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\ntry {\n\t\t\tthrow new Error(&quot;This is the error&quot;);\n\t\t} catch (Error e) {\n\t\t\te.printStackTrace();\n\t\t}\n\t\t\/\/ OR\n\t\ttry {\n\t\t\tthrow new Error(&quot;This is the error&quot;);\n\t\t} catch (Throwable e) {\n\t\t\te.printStackTrace();\n\t\t}\n<\/pre>\n<hr \/>\n<p><strong>java.lang.Exception :<\/strong><br \/>\nThe class &#8220;Exception&#8221; and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.<\/p>\n<p>All the subclasses of Exception forms the &#8220;<a title=\"Checked Exception\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/checked-unchecked-exception\/\" target=\"_blank\"><strong>Checked Exception<\/strong><\/a>&#8221; which <strong>must be caught by catch block<\/strong>.<\/p>\n<p>Example : <a title=\"ClassNotFoundException\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/ClassNotFoundException.html\" target=\"_blank\">ClassNotFoundException<\/a>, <a title=\"IOException\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/io\/IOException.html\" target=\"_blank\">IOException<\/a><\/p>\n<hr \/>\n<p><strong>java.lang.RuntimeException: <\/strong><br \/>\nThis is the subclass of the Exception class. All the classes which extends this class are known as &#8220;<a title=\"UncheckedException\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/checked-unchecked-exception\/\" target=\"_blank\"><strong>UnChecked Exception<\/strong><\/a>&#8220;. This type of exception shows that there is some logical error in program.Unlike checked exception, it is not necessary to surround the code with try-catch block.<br \/>\nExample : <a title=\"Arithmatic Exception\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/ArithmeticException.html\" target=\"_blank\">ArithmeticException <\/a>, <a title=\"NullPointerEXception\" href=\"http:\/\/download.oracle.com\/javase\/1.4.2\/docs\/api\/java\/lang\/NullPointerException.html\" target=\"_blank\">NullPointerException<\/a><\/p>\n<hr \/>\n<p><strong>Question : Although all exceptions must be caught in catch block, then what is the need of checked and unchecked exception ? Why not all the exceptions are unchecked ?<\/strong><br \/>\nAnswer : How the programmer will come to know that which type of exception occur in API ? Hard way is when it occurs at run time and easy way is &#8220;when compiler complains that Exception is not handled properly&#8221;. It is very easy to handle the exception if API shows types of possible exception thrown (Checked Exception). it will make the programers life very easy.<\/p>\n<p>Next Read &#8211;<a title=\"Exception chaining mechanism\" href=\"https:\/\/jitendrazaa.com\/blog\/java\/exception-chaining\/\" target=\"_blank\"> Read Exception chaining <\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Explain the concept of Exception and Error handling framework 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":[329],"class_list":["post-2009","post","type-post","status-publish","format-standard","hentry","category-java","tag-java"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1820,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/java-threading-executor-framework-and-callable-interface\/","url_meta":{"origin":2009,"position":0},"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":2267,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/ccb-error-resolve-unable-to-move-value-into-property\/","url_meta":{"origin":2009,"position":1},"title":"CC&#038;B error Resolve &#8211; Unable to move value into property","author":"Jitendra","date":"June 21, 2011","format":false,"excerpt":"How to resolve the error \"Unable to move value into property\" in Customer care and Billing (CC&B) \/ Oracle revenue management and billing System (ORMB) \/ Oracle Utilities","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":738,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/checked-unchecked-exception\/","url_meta":{"origin":2009,"position":2},"title":"Checked and Unchecked Exception","author":"Jitendra","date":"August 7, 2010","format":false,"excerpt":"Explains the concept of checked exception and unchecked exception in JAVA.","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":1638,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/exception-chaining\/","url_meta":{"origin":2009,"position":3},"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":1951,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/project-coin-java-7-new-features\/","url_meta":{"origin":2009,"position":4},"title":"Project Coin &#8211; Java 7 new features","author":"Jitendra","date":"April 11, 2011","format":false,"excerpt":"What is Project Coin and how it is related to JAVA","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":2783,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/dynamic-approval-process-based-on-the-apex-and-trigger\/","url_meta":{"origin":2009,"position":5},"title":"Dynamic Approval Process in Salesforce using Apex and Trigger","author":"Jitendra","date":"March 27, 2012","format":false,"excerpt":"This article explain the Automatic submission of Approval process using Apex and trigger. It include Automatic submission, approval as well as rejection of record completely using Apex and trigger.","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"Approval Process Steps","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Approval-Process-Steps.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Approval-Process-Steps.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/03\/Approval-Process-Steps.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2009","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=2009"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2009\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}