Is there a static way to throw exception in php -


is there "static" way of throwing exception in php?

i need throw exception when mysql query fails.

i tried this:

$re=@mysql_query( $query ) or throw new exception(' query failed '); 

but it's not working.

and i'm using function based on throwexception() function comment @ php: exceptions manual, know if there static way doing without making class.

you won't able directly or throw new exception(); because throw statement, not expression. since or operator, expects operands expressions (things evaluate values).

you'd have instead:

$re = mysql_query($query);  if (!$re) {     throw new exception('query failed'); } 

if you're trying use throwexception() function proposed php manual comment, webbiedave points out comment saying need call function instead of throw statement directly, this:

$re = mysql_query($query) or throwexception('query failed'); 

there's no rule in php says need throw exceptions class method. long there's way catch exception you're fine. if mean want throw exceptions without using exception class, well, have to. exceptions objects nature; can't throw exception isn't object (or doesn't inherit exception class).

if don't want throw exceptions raise kind of error see php (notices, warnings , fatal errors), use trigger_error().

$re = mysql_query($query);  if (!$re) {     trigger_error('query failed', e_user_error); } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -