Free web hosts - 575Chapter 31Exceptions and Error Handlingparent::Exception($message); } } echo
575Chapter 31Exceptions and Error Handlingparent::Exception($message); } } echo $msg; function is_valid_user ($user_id) { // throw an exception if the user ID does not begin // with usr $pre_str = usr ; if ((strpos($user_id, $pre_str) === false) || (strpos($user_id, $pre_str) != 0)) { throw new PrefixException( $user_id does not contain the proper prefix. ); } // throw an exception if the user ID is not the proper length if ((strlen($user_id) < 9)) { throw new LengthException( $user_id is less than the required length ); } if (validate($user_id)) { // user ID was found in the database return true; } else // the specified user ID does not exist in the databasereturn false; } } ?> Note that we attempted to recover from the missing prefixerror condition. You can easily dealwith individual types of errors now that they have been defined separately. Limitations of Exceptions in PHPThe Exception object is completely new in PHP5 and as such is still in the rough stages ofdevelopment. As of this writing, PHP does not support the use of finally()or throws() methods as do Java and other languages. Also, unlike other languages, native PHP errors including errors, which are normally printed to the client-side browser are not yet mappedto exceptions. Because of this, for example, a SQL statement error within a try/catch blockwill not automatically throw an exception that can be caught and dealt with. This handy func- tionality will most likely be included in a future version of PHP, so it s worth mentioning andkeeping an eye out for. Some of these errors can be dealt with using techniques described inthe next section.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.