RE: Try{} Catch()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



use it just like in JAVA, It offers a uniform/good way to  manage exception
in app.  
e.g. 
function getObjFromDB($key)
{
if (strlen($key)!=0 )
throw new Exception ("need condition .");
if (!mysql_connect(...))
throw new Exception ("can't connect to db .");
.....
}

function foo ()
{
$err='';
for (...)
{
try
{
getObjFromDB('');
}
catch (Exception $e) // if you throw a exception but didn't catch it , the
PHP app will stop and not prompt any error message.
{
	echo $e; //output the error message.
 	$err .= $e;
} 
}
echo "done , total message : {$err}";
}
 


> -----Original Message-----
> From: Al [mailto:news@xxxxxxxxxxxxx] 
> Sent: Monday, December 24, 2007 5:59 AM
> To: php-general@xxxxxxxxxxxxx
> Subject: Re:  Try{} Catch()
> 
> I understand it's intended use and how to use it, have just 
> not found a good use for it yet.
> 
> 
> 
> Martin Alterisio wrote:
> > It's not supposed to be practical, it's just a way to 
> handle errors. You
> > shouldn't rely on try/catch for algorithm implementation.
> > 
> > You create exceptions for errors and unexpected behavior. 
> Then in some other
> > part of the system you use try/catch to prevent the code 
> from terminating
> > abruptly. You catch the exception (you should know which 
> exceptions can be
> > thrown), and act accordingly. Either closing resources, add 
> a log message
> > with debug information, and/or sending an error message to the user.
> > 
> > 2007/12/23, Al <news@xxxxxxxxxxxxx>:
> >> Try() and Catch() seems neat; but, I've not found it to be 
> very practical.
> >>
> >> Anyone using it? How?
> >>
> >> Al...
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> > 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux