Welcome Guest, Not a member yet? Register   Sign In
How to load a class CI to catch Exceptions
#1

[eluser]Feathers And Down[/eluser]
Well... I want to know if &autoload; global function, defined in system/core/Common.php, can search inside previous defined packages. Hope I'm doing something wrong or if there is an alternative way to load a single class.

What I want to do is add some php Exceptions inhereted class to throw in my application, primary from model to be catched inside model/controller/libraries. First, I don't know where to put those file, maybe those classes should be inside a 'libraries/Exception' folder.

Exceptions are very simple, only two or one message string about error, but they give a really good mechanism to deal with, at least, database errors, catching them and then preparing a custom (bussines logic) error message to user.

I need a way to exceptions be found automatically and not to add require|include. Maybe using spl_autoload could be useful.

- If I write "throw new Custom_Exception( );" i get a class not found error.
- I don't want to load it as a library: $this->load->library( 'Custom_Exception' ) because it can be accessible from CI with $this->Custom_Exception...
- Doing &autoload; return an object of that class, so (hope you correct me) it must be in php symbol table, and available to whole script execution if happen exception again... But seems auto_load don't search inside packages defined before.

This is what I get when doing: echo( $path.$directory.'/'.$class.EXT. '<br/>' );
at Common.php:130

Code:
/media/programming/system/core/Benchmark.php
/media/programming/system/core/Hooks.php
/media/programming/system/core/Config.php
/media/programming/system/libraries/Log.php
/media/programming/system/core/Utf8.php
/media/programming/system/core/URI.php
/media/programming/system/core/Router.php
/media/programming/system/core/Output.php
/media/programming/system/core/Security.php
/media/programming/system/core/Input.php
/media/programming/system/core/Lang.php
/media/programming/system/core/Loader.php
/media/programming/system/core/Model.php

/media/programming/system/libraries/Custom_Exception.php
application/libraries/Custom_Exception.php

Unable to locate the specified class: Custom_Exception.php
(new lines where added by me)

Is there any other way to do that? Maybe CI need to be updated to support packages Smile


Thanks in advance.




Theme © iAndrew 2016 - Forum software by © MyBB