11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 8 • ERROR AND EXCEPTION HANDLING• DomainException: The DomainException class should be used to handle scenarioswhere an input value falls outside of a range. For instance, if a weight-lossapplication includes a method which is intended to save a user’s current weight toa database, and the supplied value is less than zero, an exception of typeDomainException should be thrown.• InvalidArgumentException: The InvalidArgumentException class should be used tohandle situations where an argument of an incompatible type is passed to afunction or method.• LengthException: The LengthException class should be used to handle situationswhere a string’s length is invalid. For instance, if an application included a methodthat processed a user’s social security number, and a string was passed into themethod that was not exactly nine characters in length, then an exception of typeLengthException should be thrown.• LogicException: The LogicException class is one of the two base classes fromwhich all other SPL exceptions extend (the other base class beingRuntimeException class). You should use the LogicException class to handlesituations where an application is programmed incorrectly, such as when there isan attempt to invoke a method before a class attribute has been set.• OutOfBoundsException: The OutOfBoundsException class should be used to handlesituations where a provided value does not match any of an array’s defined keys.• OutOfRangeException: The OutOfRangeException class should be used to handle afunction’s output values which fall outside of a predefined range. This differs fromDomainException in that DomainException should focus on input rather thanoutput.• OverflowException: The OverflowException class should be used to handlesituations where an arithmetic or buffer overflow occurs. For instance, you wouldtrigger an overflow exception when attempting to add a value to an array of apredefined size.• RangeException: Defined in the documentation as the runtime version of theDomainException class, the RangeException class should be used to handlearithmetic errors unrelated to overflow and underflow.• RuntimeException: The RuntimeException class is one of the two base classes fromwhich all other SPL exceptions extend (the other base class being LogicExceptionclass) and is intended to handle errors which only occur at runtime.• UnderflowException: The UnderflowException class should be used to handlesituations where an arithmetic or buffer underflow occurs. For instance, youwould trigger an underflow exception when attempting to remove a value from anempty array.• UnexpectedValueException: The UnexpectedValueException class should be used tohandle situations where a provided value does not match any of a predefined setof values.189

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!