Re: Really quick try/catch question

From: Date: Tue, 18 Aug 2009 19:55:32 +0000
Subject: Re: Really quick try/catch question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-296942@lists.php.net to get a copy of this message
On Tue, Aug 18, 2009 at 1:29 PM, Brian Dunning <brian@briandunning.com>wrote: > I have a "new SimpleXMLElement()" that is occasionally throwing: > 'Exception: String could not be parsed as XML' > > Will this catch it when it happens, or am I missing something? > > function domyfunction() { > // This does some stuff to exit the script gracefully > } > > try { > $xmlobject = new SimpleXMLElement($xml); > } catch($e) { > domyfunction($e); > } you need to add the name of the class you want to capture, or an ancestor thereof, try { .. } catch(Exception $e) { .. } -nathan

« previous php.general (#296942) next »