I just saw Daniel changing some of the PEAR classes to use Exceptions,
and it's pretty clear that this could cause havoc with the end users.
The problem being that there is no 'soft' landing for the migration process.
Users switching code from return style error handling to exceptions are
not given any hints about what would be affected, and what may need fixing.
This is mainly due to the fact that Exceptions can occur anywhere inside
of multiple nested function calls, and failure to catch them is
frequently due to missing the fact that a dependent library of function
call could raise an exception.
So in looking at how this could be addressed, I thought I'd throw this
idea out there and see how it bounced..
PHP enforces rules like $this can not be used in a method marked
'static'. So why not flag methods (and internal functions) with a flag
that indicates they can throw things. Since PHP is not a compiled
language we can not pick up 'all' of the potential scenarios, but even
if E_NOTICE's pick up 80% it would make code considerably more maintainable.
So this is the rough outline..
Existing code that throws exception
1: function throwSomething() {
2: ...
3: throw new Exception
4: }
Would produce Compile-time warning: "E_NOTICE: throw used inside
non-catchable function on line 3"
The remove the warning:
1: catchable function throwSomething() {
2: ...
3: throw new Exception
4: }
Calling a function
1: function callThrow()
2: {
3: $this->throwSomething();
4: }
Would produce Run-time warning: "E_NOTICE catchable method called inside
non-catchable function or try/catch on line 3"
Fix:
either wrap the call in try/catch or make the function catchable.
Anyway... flame away ;)
Regards
Alan
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php