{"id":2687,"date":"2017-11-25T19:33:07","date_gmt":"2017-11-25T19:33:07","guid":{"rendered":"http:\/\/webartdevelopers.com\/?p=2687"},"modified":"2017-11-25T19:33:22","modified_gmt":"2017-11-25T19:33:22","slug":"how-to-create-a-custom-exception-and-handle-excption-with-it-in-core-java","status":"publish","type":"post","link":"https:\/\/webartdevelopers.com\/blog\/how-to-create-a-custom-exception-and-handle-excption-with-it-in-core-java\/","title":{"rendered":"How to Create a Custom Exception and Handle Exception with it  in Core Java"},"content":{"rendered":"<p>In this tutorial how to create a Custom Exception and Handle Exception with it in Core Java\u00a0 is shown.<\/p>\n<p>Code:<\/p>\n<p>ExceptionDemo1.java<\/p>\n<p>class MyException extends Exception<br \/>\n{<br \/>\nMyException()<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>class ExceptionDemo1<br \/>\n{<br \/>\npublic static void main(String[] args)<br \/>\n{<br \/>\nMyException ex=new MyException();<br \/>\n}<br \/>\n}<\/p>\n<p><a href=\"https:\/\/youtu.be\/kIGZ5GQXL8o\">https:\/\/youtu.be\/kIGZ5GQXL8o<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"In this tutorial how to create a Custom Exception and Handle Exception with it in Core Java\u00a0 is shown. Code: ExceptionDemo1.java class MyException extends Exception { MyException() { 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;); } } } class ExceptionDemo1 { public static void main(String args) { MyException ex=new MyException(); } }<!-- 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,185,150],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2687"}],"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=2687"}],"version-history":[{"count":3,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2687\/revisions"}],"predecessor-version":[{"id":2690,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/posts\/2687\/revisions\/2690"}],"wp:attachment":[{"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/media?parent=2687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/categories?post=2687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webartdevelopers.com\/blog\/wp-json\/wp\/v2\/tags?post=2687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}