Welcome Guest, Not a member yet? Register   Sign In
Struggling with extending CI_Exceptions
#1

[eluser]Unknown[/eluser]
I recently started developing with CodeIgniter and it has been a great help for me. But at the moment I'm struggling with handling my errors/exceptions and so I needed to extended the base CI_Exceptions class. I have done something similar with the core Controller and it worked very good.

So I did the same:

- I created inside application/libraries a class with my prefix (CL_) : CL_Exceptions
- The class extends from CI_Exceptions
- I added some code for doing stack traces and e-mailing

But none of the functionality gets overridden. The class is autoloaded: I can see if deliberately add some erroneous code.
What might be the problem?

Here is the class:

Code:
<?php

class CL_Exceptions extends CI_Exceptions
{
    public function __construct()
    {
        parent::__construct();
    }
    
    function show_error($heading, $message, $template = 'error_general', $status_code = 500) {
        try {
            $str = parent::show_error($heading, $message, $template = 'error_general', $status_code = 500);
        
            throw new Exception($str);
        } catch (Exception $e) {
            $msg = $e->getMessage();
            $trace = "<h1>Call Trace</h1><pre>". $e->getTraceAsString(). "<pre>";
    
            //append our stack trace to the error message
            $err = str_replace('</div>', $trace . '</div>', $msg);
    
            echo $err;
        }
    }
}
#2

[eluser]Cambo[/eluser]
Hi
I also am having trouble extending the exceptions class.
Possibly the problem with your code is that you have said the parent is the construct instead of the original class.
Code:
public function __construct()
    {
        parent::__construct();
    }

I think it should be:

Code:
public function __construct()
    {
        parent::CI_Exceptions();
    }
Regards
Cambo
#3

[eluser]Rushino[/eluser]
got the same problem and i can't find a solution.




Theme © iAndrew 2016 - Forum software by © MyBB