Is there a "static" way of throwing an exception in php?
I need to throw an exception when a 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 a function based on the throwException()
function from this comment at PHP: Exceptions manual, but I would like to know if there is a static way for doing this without making a class.
The comment you link to states that throwing an exception in this way will not work. It states you have to place it in a function:
function throwException($message = null, $code = null) {
throw new Exception($message, $code);
}
$re = mysql_query($query) or throwException('Query Failed');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With