{"id":1613,"date":"2009-08-04T01:44:24","date_gmt":"2009-08-03T20:44:24","guid":{"rendered":"http:\/\/www.chiragmehta.info\/chirag\/?p=1613"},"modified":"2009-08-04T01:45:53","modified_gmt":"2009-08-03T20:45:53","slug":"apex-how-to-throw-a-custom-built-exception","status":"publish","type":"post","link":"https:\/\/www.chiragmehta.info\/chirag\/2009\/08\/04\/apex-how-to-throw-a-custom-built-exception\/","title":{"rendered":"Apex : How to throw a custom built Exception"},"content":{"rendered":"<p>If you want to throw an exception in an apex class, following code will help ..<\/p>\n<p>First you have to create your own Exception class like this:<\/p>\n<blockquote><p>public class applicationException extends Exception {}<\/p><\/blockquote>\n<p>Then you can throw an exception using following syntax<\/p>\n<blockquote><p>throw new applicationException(&#8216;House Full&#8217;);<\/p><\/blockquote>\n<p><\/p>\n<p>For e.g.,<\/p>\n<blockquote><p>public class MyException extends Exception {}<br \/>\ntry {<br \/>\nInteger i;<br \/>\n\/\/ Your code here<br \/>\nif (i &lt; 5) throw new MyException();<br \/>\n} catch (MyException e) {<br \/>\n\/\/ Your MyException handling code here<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If you want to throw an exception in an apex class, following code will help .. First you have to create your own Exception class like this: public class applicationException extends Exception {} Then you can throw an exception using following syntax throw new applicationException(&#8216;House Full&#8217;); For e.g., public class MyException extends Exception {} try [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[169],"class_list":["post-1613","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-salesforce","post-preview"],"_links":{"self":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/comments?post=1613"}],"version-history":[{"count":3,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1613\/revisions"}],"predecessor-version":[{"id":1616,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/posts\/1613\/revisions\/1616"}],"wp:attachment":[{"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/media?parent=1613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/categories?post=1613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chiragmehta.info\/chirag\/wp-json\/wp\/v2\/tags?post=1613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}