{"id":2684,"date":"2017-11-25T19:27:36","date_gmt":"2017-11-25T19:27:36","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2684"},"modified":"2017-11-25T19:27:36","modified_gmt":"2017-11-25T19:27:36","slug":"how-to-raise-an-exception-using-throw-keyword-and-how-to-use-finally-keyword-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-raise-an-exception-using-throw-keyword-and-how-to-use-finally-keyword-in-core-java\/","title":{"rendered":"How to Raise an Exception using Throw Keyword and How to use Finally Keyword in Core Java"},"content":{"rendered":"<p>In this tutorial how to raise an Exception using throw Keyword and how to use finally Keyword in Core Java\u00a0 is shown.<\/p>\n<p>Code:<\/p>\n<p>ExceptionThrow.java<\/p>\n<p>class ExceptionThrow<br \/>\n{<br \/>\npublic static void main(String args[])<br \/>\n{<br \/>\ntry<br \/>\n{<br \/>\nfor(int i=0;i&lt;5;i++)<br \/>\n{<br \/>\nif(i==3)<br \/>\nthrow new Exception();<br \/>\nelse<br \/>\nSystem.out.println(&#8220;i: &#8220;+i);<br \/>\n}<br \/>\n}<br \/>\ncatch(Exception e)<br \/>\n{<br \/>\nSystem.out.println(&#8220;Exception raised&#8221;);<br \/>\n}<br \/>\nfinally<br \/>\n{<br \/>\nSystem.out.println(&#8220;finally is called&#8221;);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/k18Pia4p9es\">https:\/\/youtu.be\/k18Pia4p9es<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how to raise an Exception using throw Keyword and how to use finally Keyword in Core Java\u00a0 is shown. Code: ExceptionThrow.java class ExceptionThrow { public static void main(String args) { try { for(int i=0;i&lt;5;i++) { if(i==3) throw new Exception(); else System.out.println(&#8220;i: &#8220;+i); } } catch(Exception e) { System.out.println(&#8220;Exception raised&#8221;); } finally { System.out.println(&#8220;finally is called&#8221;); } } }<!-- AddThis Advanced Settings generic via filter on get_the_excerpt -->","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156],"tags":[157,150,184,182],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2684"}],"collection":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/comments?post=2684"}],"version-history":[{"count":2,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2684\/revisions"}],"predecessor-version":[{"id":2686,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2684\/revisions\/2686"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}