Welcome Guest, Not a member yet? Register   Sign In
How to instance an exception in the controller
#1

[eluser]jeffersonrpn[/eluser]
To show a error message in the user interface (view) I throw exceptions from the models to controller. But I can't create exceptions in the controller using $this->load->model( 'My_exception' ); because this model don't extends a Model Class, but a Exception Class. Check the constructor method:

Code:
class My_exception extends Exception {

  [...]
  public function __construct( $message, $title, $level ) {
    parent::__construct( $message );
    $this->title = $title;
    $this->level = $level;
  }
  [...]

}

How I can instance a model in the controller that don't extends a Model Class?
#2

[eluser]Michael Wales[/eluser]
Why not just include() it?

EDIT:
Actually - looking over it a bit more... your extended Exception class should be auto-loaded (since it's named My_Exception).

Does this not work?
Code:
$err = new My_Exception($msg, $title, $level);




Theme © iAndrew 2016 - Forum software by © MyBB