![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 16
Rep Power: 0
![]() |
Catching exceptions up the stack
Howdy all,
The problem I'm having is catching an exception at the top layer of a script, that is thrown from a lower level. Exceptions *should* travel all the way up the stack, looking for a catch statement, until the end of the stack is reached. But that's not working for me. Here is a code example: class Foo
{
public function __construct()
{
throw new Exception('Oh no!');
}
}
class Bar
{
public function __construct()
{
$Foo = new Foo;
}
}
class MyClass
{
public function __construct()
{
$Bar = new Bar;
}
}
try {
$MC = new MyClass;
} catch (Exception $e) {
die($e->getMessage());
}Even though the exception is thrown in the Foo class, which is the third class initiated, the exception *should* bubble-up and get caught in the try...catch statement. But it doesn't. PHP will die with a uncaught exception fatal error. Actually the above code works just fine. But the code I'm working on now is basically the same, only it's a lot more code. It's an object created by an object, created by an object, created by an object, which finally has a try...catch statement. The deepest object throws the exception, and it's not bubbling-up to the try...catch statement. So is there a limit on how far up the stack PHP will go to find a try...catch clause? |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Heap vs. Stack memory | Eric the Red | C++ | 11 | Oct 24th, 2006 7:18 PM |
| Combining languages | titaniumdecoy | Other Programming Languages | 12 | Jul 13th, 2006 3:03 PM |
| Assembly tutorial, part one. | Mad_guy | Software Design and Algorithms | 21 | Apr 15th, 2006 8:02 PM |
| A noob to Assembly | CodeJunkie | Assembly | 12 | Jan 25th, 2006 3:06 PM |
| Smashing a stack in MIPS assembly code | tsgrimey | Assembly | 2 | Feb 27th, 2005 2:06 PM |