Jump to content

Question on throwing exceptions


ericm

Recommended Posts

I've been reading up on some of the new features found in PHP5 and am a bit unclear on the use of throwing exceptions.  In some of the sample code I've seen, exceptions are thrown as an error catching mechanism.

 

if (!$mySQL)

{

    throw new MySQLException();

}

 

That's all fine, but what I don't see is how this differs from a standard function call in the case of !$mySQL.  What advantages (or disadvantages) would exception throwing offer over a function?  What is the proper useage?

 

And lastly, in my research to find an answer or better understanding, there has been some debate on creating child exception classes (like MySQLException) and to what degree -- having a top level MySQLException class vs. having specific MySQL related exception classes (ie - MySQLConnectionException, MySQLQueryException).  Which is the better approach and why?

Link to comment
https://forums.phpfreaks.com/topic/120921-question-on-throwing-exceptions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.