I've been coding in PHP for a very long time but only recently got into doing things the OO way due to being a retard. The OO way does appear to be a very lovely way.
Got a (probably simple) question about Exception Handling though. Let's say I have three classes, like so...
... do I need that "intermediary" try/catch clause in ClassTwo, to re-throw the Exception from ClassOne, or if I leave it out will the Exception naturally keep getting passed back up the chain until it reaches ClassThree's try/catch?
Got a (probably simple) question about Exception Handling though. Let's say I have three classes, like so...
PHP:
class ClassThree {
private $obj;
function __construct() {
try {
$this->obj = new ClassTwo();
}
catch(Exception $e) {
print 'Sorry guy, the bad stuff happen ('.$e->message.')';
}
}
}
class ClassTwo {
private $obj;
function __construct() {
try {
$this->obj = new ClassOne();
}
catch(Exception $e) {
throw $e;
}
}
}
class ClassOne {
function __construct() {
throw new Exception('oh no and error message');
}
}
... do I need that "intermediary" try/catch clause in ClassTwo, to re-throw the Exception from ClassOne, or if I leave it out will the Exception naturally keep getting passed back up the chain until it reaches ClassThree's try/catch?