ericm Posted August 22, 2008 Share Posted August 22, 2008 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 More sharing options...
Mchl Posted August 22, 2008 Share Posted August 22, 2008 Different classes of exceptions can be "caught" by different catch blocks. This way you can control, on which level given exception should be handled. (To be honest, I am also still on the stage of grasping this idea...) Link to comment https://forums.phpfreaks.com/topic/120921-question-on-throwing-exceptions/#findComment-623320 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.