News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Reddit.com:
When do you throw exceptions?
September 20, 2013 @ 10:45:04

On Reddit.com there's a discussion that's started up around when to throw exceptions in your PHP applications. The poster asks:

When and where do you throw exceptions? Is it just on database connections? Is it whenever you run a query? Send an email? I'm just curious what the best situations are to throw exceptions and possibly improve my code.

There's a good number of replies so far, some a bit more vague than others:

  • "In exceptional circumstances."
  • "You throw an except when you can't sensibly handle what has just happened."
  • "Fatals for compile-time errors, Exceptions for run-time errors"
  • "I throw an exception any time the function being called is either not capable of continuing or it is not going to return the expected results."
  • "Exceptions everywhere is not a good thing."

Check out more suggestions and comments in the full post.

0 comments voice your opinion now!
exceptions throw opinion conversation

Link: http://www.reddit.com/r/PHP/comments/1mr1qa/when_do_you_throw_exceptions

NetTuts.com:
Round Table #1 Should Exceptions Ever be Used for Flow Control?
March 28, 2013 @ 10:20:39

On the NetTuts.com site today they've posted the transcript of a panel discussion they had with several developers about exceptions and whether or not they should be used for flow control.

I'm pleased to release our first ever round table, where we place a group of developers in a locked room (not really), and ask them to debate one another on a single topic. In this first entry, we discuss exceptions and flow control.

The opinions vary among the group as to what exceptions should be used for (even outside of the flow control topic). Opinions shared are things like:

  • Exceptions are situations in your code that you should never reach
  • Errors cause Failures and are propagated, via Exceptions.
  • So, essentially, exceptions are an "abstraction" purely to model the abnormality.
  • Personally, I envision exceptions more as "objections."
  • Exceptions like this should be caught at some point and transformed into a friendly message to the user.

There's lots more than this in the full discussion so head over and read it all - there's definitely some good points made.

0 comments voice your opinion now!
roundtable exceptions flow control panel discussion


Padraic Brady's Blog:
Contributing To Zend Framework 2.0 Is Free! Hurry Before This Offer Ends!
September 21, 2010 @ 09:54:13

In Padraic Brady's latest post he makes a pitch for developers out there to get in on the development of the Zend Framework version 2.0 "before the offer ends" in a few different ways.

Zend Framework 2.0 recently passed Milestone 1 on its development track and is rocking on PHP 5.3 in all its namespaced glory. Milestone 2 is the introduction of the new Exception regime to ensure all of the frameworks' fun components throw Exceptions that are specific enough to be useful. Why waste your idleness on the Devil's work when you can be bringing salvation to armies of PHP programmers?

He links to some great resources if you want to get involved including the list of who's working on the exceptions handling, a link to the components and maintainers list for the framework and at getting started with Git guide to introduce you to the version control you'll need to use.

1 comment voice your opinion now!
zendframework contribute exceptions framework git project


Jani Hartikainen's Blog:
The "do X or die()" pattern must die
July 29, 2010 @ 09:19:03

Jani Hartikainen has a suggestion for all PHP developers out there - stop using die() for handling errors!

What's the most common pattern for error handling you see in beginner's PHP code? - That's right, do_X() or die('do_X failed);. That's nice and all, as at least you have some sort of error handling, but I think this way of handling errors must go. There is no place for it in modern PHP code - it's the worst way to handle errors, not much better than not handling them at all.

He talks about why die() is so bad and some alternatives to it - trigger_error (with a custom error handler) and exceptions. When used correctly, these two can help your script correctly catch and handle errors without the mess of a die().

0 comments voice your opinion now!
die pattern triggererror exceptions error


Tibo Beijen's Blog:
Catching PHP Exceptions Except the unexpected
October 27, 2009 @ 10:21:43

Tibo Beijen has a new post to his blog today looking at exception handling starting with some of the basics and moving out to custom exception handing methods.

Before PHP5 one had to resort to specific return values or drastic measures like trigger_error(). Planning exceptions, I found out, is just as important as class design. At any point where a developer needs to handle the possibility of an exception being thrown he needs to know: what Exceptions can I expect and what Exceptions do I plan to catch? In this post I'll show some important aspects to consider when planning exceptions.

He starts off with a basic example of an exception, throwing it and catching it, as a part of a SOAP client sample and looks at things to catch, how to catch them and doing fun things like rethrowing and extending basic exception types.

0 comments voice your opinion now!
exceptions tutorial expect


Alexander Netkachev's Blog:
PHP coding tip Convert notices and warnings into Exceptions
October 18, 2006 @ 07:19:54

Exceptions and warnings can be tossed out from your code at some odd locations sometimes. There's a few options that you have when they jump out, including pushing them out to an error log or just ignoring them completely. Alexander Netkachev has a different solutions, though - handling them with something already built into PHP, using exception reporting.

This coding tip demonstrates how to deal with PHP core notices and warning (aka recoverable errors) in the exception way, using try/catch statement.

IT's a simple idea, but it can definitely help you keep all of you errors in one place. The sample code he gives shows both a basic idea of the solution and a bit more complex example, providing more detailed messages for different exception types.

0 comments voice your opinion now!
warnings notices exceptions convert handling try catch warnings notices exceptions convert handling try catch


Developer.com:
PHP 5 OOP - Delegation and Custom Exceptions
May 23, 2006 @ 12:06:36

Developer.com has posted the next part in their series covering object oriented programming in PHP5, this time focusing on using delegation to enhance the functionality of their prexisting DBQuery class.

At present our DBQuery object simply mimics (all be it - rather simply) a stored procedure. Once executed a result resource is returned which you must store and pass the MySqlDB object if you wish to use functions such as num_rows() or fetch_row() on the result set. Would it not be nice if the DBQuery object were able to implement the functions which the MySqlDB object implements; that are designed to work on the result of an executed query?

They explain each step of the way, giving you the code you'll need to attach to the current working script, making this delegation possible. They look briefly at tpye hinting and simple exception handling in the script before hitting you with a full-blown Exception handler class to improve your script's reliability.

0 comments voice your opinion now!
php5 oop delegation custom exceptions part3 tutorial php5 oop delegation custom exceptions part3 tutorial


SitePoint PHP Blog:
PHP to the Rescue!
May 01, 2006 @ 07:34:45

In his latest post on the SitePoint PHP Blog, Harry Fuecks has linked to a rather long look at error codes and exceptions in PHP, courtesy on Damien Katz.

If you're looking for a thoughtful Saturday read, you won't go far wrong with Error codes or Exceptions? Why is Reliable Software so Hard? by Damien Katz, which is worth it just for the visual interludes.

In fact it's less about error codes / exceptions and more about what you do when something does go wrong-how to you "bail out" of the mess you're in?

There's a few different error handling types that Damien mentions

, including the "Get the Hell Out of Dodge" Error Handling, "Reverse the Flow of Time" Error Handling, and "Plan B" Error Handling as well as some suggestions to help you and your code cope.
0 comments voice your opinion now!
error handling codes exceptions reliable software tips types error handling codes exceptions reliable software tips types


DevShed:
Error Handling in PHP - Introducing Exceptions in PHP 5
January 19, 2006 @ 06:53:22

Today, Devshed as posted the second and last part in their "Error Handling in PHP" series - Introducing Exceptions in PHP 5.

Welcome to the last part of the series "Error Handling in PHP." In two parts, this series introduces the basics of error handling in PHP. It demonstrates some of the most common methods for manipulating errors in PHP 4, and explains the implementation of exceptions in PHP 5, particularly in object-oriented environments.

They introduce things like try/catch blocks as well as more complex items like custom exceptions and exception subclassing. They start with the basics, but quickly move into grabbing more detailed error information, working with the various error types, and extending the Exception class with subclasses to make it more flexible...

0 comments voice your opinion now!
error handling part two introducing exceptions php5 error handling part two introducing exceptions php5



Community Events





Don't see your event here?
Let us know!


composer community symfony security artisanfiles list library podcast laravel framework release tool series interview voicesoftheelephpant version opinion conference introduction language

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework