{"id":277,"date":"2012-06-24T21:52:31","date_gmt":"2012-06-24T16:22:31","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=277"},"modified":"2012-06-24T21:52:31","modified_gmt":"2012-06-24T16:22:31","slug":"set_exception_handler-function-within-a-class-for-example-codeigniter","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/php\/set_exception_handler-function-within-a-class-for-example-codeigniter\/","title":{"rendered":"set_exception_handler function within a class for example codeigniter"},"content":{"rendered":"<p>Here is how to use the set_exception_handler function within a class<\/p>\n<p>the defined exception_handler method must be declared as public preferably public static if using the array syntax like array(&#8216;Abc&#8217;, &#8216;exception_handler&#8217;) <em>as suggested in php.net site.<\/em><\/p>\n<pre lang='php'>\r\nclass Abc extends CI_Controller {\r\n\r\n    function __construct()\r\n    {\r\n        parent::__construct();\r\n        set_exception_handler(array('Abc', 'exception_handler');\r\n        \/\/also you can use array($this, 'exception_handler')     \r\n    }       \r\n\r\n    function exception_handler(Exception $ex)\r\n    {        \r\n        echo $ex->getMessage();\r\n    }\r\n\r\n    function Index()\r\n    {\r\n        throw new Exception('hehe');\r\n    }\r\n}   \r\n\r\n<\/pre>\n<p>The exception handler must be defined before calling set_exception_handler()<\/p>\n<p>so the above code sets the default exception handler if an exception is not caught within a try\/catch block. Execution will stop after the exception_handler is called. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is how to use the set_exception_handler function within a class the defined exception_handler method must be declared as public preferably public static if using the array syntax like array(&#8216;Abc&#8217;, &#8216;exception_handler&#8217;) as suggested in php.net site. class Abc extends CI_Controller { function __construct() { parent::__construct(); set_exception_handler(array(&#8216;Abc&#8217;, &#8216;exception_handler&#8217;); \/\/also you can use array($this, &#8216;exception_handler&#8217;) } function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[34,42],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/277"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":1,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/277\/revisions"}],"predecessor-version":[{"id":278,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/277\/revisions\/278"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}