Prev | Current Page 287 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

If you??™d like to log the error message as provided by the PHP engine, you can include
the string %m in the message. This string will be replaced by the error message string
(strerror) as offered by the engine at execution time.
Now that you??™ve been acquainted with the relevant functions, here??™s an example:
define_syslog_variables();
openlog("CHP8", LOG_PID, LOG_USER);
syslog(LOG_WARNING,"Chapter 8 example warning.");
closelog();
?>
This snippet would produce a log entry in the messages syslog file similar to the
following:
Dec 5 20:09:29 CHP8[30326]: Chapter 8 example warning.
CHAPTER 8 ?–  ERRO R AND EXCEPTION HANDL ING 221
Exception Handling
Languages such as Java, C#, and Python have long been heralded for their efficient
error-management abilities, accomplished through the use of exception handling.
If you have prior experience working with exception handlers, you likely scratch your
head when working with any language, PHP included, that doesn??™t offer similar capabilities.
This sentiment is apparently a common one across the PHP community
because, as of version 5, exception-handling capabilities have been incorporated into
the language. In this section, you??™ll learn all about this feature, including the basic
concepts, syntax, and best practices. Because exception handling is new to PHP, you
may not have any prior experience incorporating this feature into your applications.


Pages:
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299