Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Dec 27th, 2006, 1:00 AM   #1
headzoo
Newbie
 
Join Date: Oct 2006
Posts: 16
Rep Power: 0 headzoo is on a distinguished road
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?
headzoo is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC