Welcome Guest, Not a member yet? Register   Sign In
setting an exception handler
#1

[eluser]fuchong[/eluser]
Hello I'm trying to write an exception handler helper that will catch any uncaught exceptions that a program might throw. I would like to use the following code which is inside my helper - the helper is autoloaded.

Code:
if ( ! function_exists('exception_handler'))
{
    function exception_handler($exception){
            $CI =& get_instance();
            $CI->load->view('errors', array('error_message'=>$exception->getMessage()));
    }
}

set_exception_handler('exception_handler');

Now with this code the view doesn't show up. However, if I modify it and use this code:

Code:
if ( ! function_exists('exception_handler'))
{
    function exception_handler($exception){
            $CI =& get_instance();
            echo $CI->load->view('errors', array('error_message'=>$exception->getMessage()), true);
    }
}

set_exception_handler('exception_handler');

the contents from the view will be returned and echo'd just fine. Now the difference between these two is that the first code snippet takes the data from the view and passing the view's information from loader to the output class(where within the output class it fails), whereas the second code snippet is just returned from the loader in which I'm allowed to echo it out.

So my question is: why does the output class fail when there is an uncaught exception?

Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB