SlideShare a Scribd company logo
PHP -  Introduction to PHP Error Handling
Introduction to PHPIntroduction to PHP
Error HandlingError Handling
TypesTypes
There are 12 unique error types, which can
be grouped into 3 main categories:
• Informational (Notices)
• Actionable (Warnings)
• Fatal
Informational ErrorsInformational Errors
• Harmless problem, and can be avoided through
use of explicit programming.
e.g. use of an undefined variable, defining a string
without quotes, etc.
Actionable ErrorsActionable Errors
• Indicate that something clearly wrong has
happened and that action should be taken.
e.g. file not present, database not available,
missing function arguments, etc.
Fatal ErrorsFatal Errors
• Something so terrible has happened during
execution of your script that further
processing simply cannot continue.
e.g. parsing error, calling an undefined
function, etc.
Identifying ErrorsIdentifying Errors
E_STRICT Feature or behaviour is depreciated (PHP5).
E_NOTICE Detection of a situation that could indicate a problem,
but might be normal.
E_USER_NOTICE User triggered notice.
E_WARNING Actionable error occurred during execution.
E_USER_WARNING User triggered warning.
E_COMPILE_WARNING Error occurred during script compilation (unusual)
E_CORE_WARNING Error during initialization of the PHP engine.
E_ERROR Unrecoverable error in PHP code execution.
E_USER_ERROR User triggered fatal error.
E_COMPILE_ERROR Critical error occurred while trying to read script.
E_CORE_ERROR Occurs if PHP engine cannot startup/etc.
E_PARSE Raised during compilation in response to syntax error
notice
warning
fatal
Causing errorsCausing errors
• It is possible to cause PHP at any point in your
script.
trigger_error($msg,$type);
e.g.
…
if (!$db_conn) {
trigger_error(‘db conn
failed’,E_USER_ERROR);
}
…
PHP Error HandlingPHP Error Handling
Customizing ErrorCustomizing Error
HandlingHandling
• Generally, how PHP handles errors is defined
by various constants in the installation (php.ini).
• There are several things you can control in
your scripts however..
Set error reportingSet error reporting
settingssettings
error_reporting($level)
This function can be used to control which
errors are displayed, and which are simply
ignored. The effect only lasts for the duration
of the execution of your script.
Set error reporting settingsSet error reporting settings
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);
// Report ALL PHP errors
error_reporting(E_ALL);
?>
Set error reportingSet error reporting
settingssettings
• Hiding errors is NOT a solution to a problem.
• It is useful, however, to hide any errors
produced on a live server.
• While developing and debugging code,
displaying all errors is highly recommended!
Suppressing ErrorsSuppressing Errors
• The special @ operator can be used to
suppress function errors.
• Any error produced by the function is
suppressed and not displayed by PHP
regardless of the error reporting setting.
Suppressing ErrorsSuppressing Errors
$db = @mysql_connect($h,$u,
$p);
if (!$db) {
trigger_error(‘blah’,E_USER_
ERROR);
}
Suppressing ErrorsSuppressing Errors
$db = @mysql_connect($h,$u,$p);
if (!$db) {
trigger_error(blah.',E_USER_ERROR
);
}
$db = @mysql_connect($h,$u,$p);
Attempt to connect to
database. Suppress error
notice if it fails..
Suppressing ErrorsSuppressing Errors
$db = @mysql_connect($h,$u,$p);
if (!$db) {
trigger_error(‘blah’,E_USER_ERROR);
}
Since error is suppressed, it
must be handled gracefully
somewhere else..
Suppressing ErrorsSuppressing Errors
• Error suppression is NOT a solution to a
problem.
• It can be useful to locally define your own
error handling mechanisms.
• If you suppress any errors, you must check
for them yourself elsewhere.
Custom Error HandlerCustom Error Handler
• You can write your own function to handle
PHP errors in any way you want.
• You simply need to write a function with
appropriate inputs, then register it in your
script as the error handler.
• The handler function should be able to
receive 4 arguments, and return true to
indicate it has handled the error…
Custom Error HandlerCustom Error Handler
function err_handler(
$errcode,$errmsg,$file,$lineno) {
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
return true;
}
Custom Error HandlerCustom Error Handler
function err_handler(
$errcode,$errmsg,$file,$lineno) {
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
return true;
}
$errcode,$errmsg,$file,$lineno) {
The handler must have 4 inputs..
1.error code
2.error message
3.file where error occurred
4.line at which error occurred
Custom Error HandlerCustom Error Handler
function err_handler(
$errcode,$errmsg,$file,$lineno) {
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
return true;
}
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
Any PHP statements can be
executed…
Custom Error HandlerCustom Error Handler
function err_handler(
$errcode,$errmsg,$file,$lineno) {
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
return true;
}
return true;
Return true to let PHP know
that the custom error handler
has handled the error OK.
Custom Error HandlerCustom Error Handler
• The function then needs to be registered as your
custom error handler:
set_error_handler(‘err_handler’);
• You can ‘mask’ the custom error handler so it
only receives certain types of error. e.g. to
register a custom handler just for user triggered
errors:
set_error_handler(‘err_handler’,
E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR);
Custom Error HandlerCustom Error Handler
• A custom error handler is never passed
E_PARSE, E_CORE_ERROR or
E_COMPILE_ERROR errors as these are
considered too dangerous.
• Often used in conjunction with a ‘debug’
flag for neat combination of debug and
production code display..
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-mumbai.html

More Related Content

PPT
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
PPT
SQLITE Android
Sourabh Sahu
 
PPTX
servlet in java
sowfi
 
PPTX
PHP Presentation
JIGAR MAKHIJA
 
PPTX
Servlets
ZainabNoorGul
 
PPTX
JAVA AWT
shanmuga rajan
 
PPT
Mvc architecture
Surbhi Panhalkar
 
PDF
Php array
Nikul Shah
 
PHP - Introduction to PHP Cookies and Sessions
Vibrant Technologies & Computers
 
SQLITE Android
Sourabh Sahu
 
servlet in java
sowfi
 
PHP Presentation
JIGAR MAKHIJA
 
Servlets
ZainabNoorGul
 
JAVA AWT
shanmuga rajan
 
Mvc architecture
Surbhi Panhalkar
 
Php array
Nikul Shah
 

What's hot (20)

PPT
Cookies in servlet
chauhankapil
 
PPT
PHP variables
Siddique Ibrahim
 
PPT
RichControl in Asp.net
Bhumivaghasiya
 
PPT
Introduction to JavaScript
Andres Baravalle
 
PPT
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
PPTX
Java servlets and CGI
lavanya marichamy
 
PPTX
Asp.Net Core MVC with Entity Framework
Shravan A
 
PPT
Java Servlets
BG Java EE Course
 
PDF
4.2 PHP Function
Jalpesh Vasa
 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
 
PPTX
Java Beans
Ankit Desai
 
PPTX
android sqlite
Deepa Rani
 
PPT
Input output streams
Parthipan Parthi
 
PPTX
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
PPT
Servlet life cycle
Venkateswara Rao N
 
PPTX
Normalization in DBMS
Prateek Parimal
 
PDF
Servlet and servlet life cycle
Dhruvin Nakrani
 
PPS
Jdbc architecture and driver types ppt
kamal kotecha
 
PDF
VB net lab.pdf
Prof. Dr. K. Adisesha
 
Cookies in servlet
chauhankapil
 
PHP variables
Siddique Ibrahim
 
RichControl in Asp.net
Bhumivaghasiya
 
Introduction to JavaScript
Andres Baravalle
 
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Java servlets and CGI
lavanya marichamy
 
Asp.Net Core MVC with Entity Framework
Shravan A
 
Java Servlets
BG Java EE Course
 
4.2 PHP Function
Jalpesh Vasa
 
Php Tutorials for Beginners
Vineet Kumar Saini
 
Java Beans
Ankit Desai
 
android sqlite
Deepa Rani
 
Input output streams
Parthipan Parthi
 
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
Servlet life cycle
Venkateswara Rao N
 
Normalization in DBMS
Prateek Parimal
 
Servlet and servlet life cycle
Dhruvin Nakrani
 
Jdbc architecture and driver types ppt
kamal kotecha
 
VB net lab.pdf
Prof. Dr. K. Adisesha
 
Ad

Viewers also liked (7)

PDF
Exceptions in PHP
JanTvrdik
 
PDF
Php exceptions
Damian Sromek
 
PDF
Errors, Exceptions & Logging (PHP Hants Oct '13)
James Titcumb
 
PDF
Elegant Ways of Handling PHP Errors and Exceptions
ZendCon
 
PPT
Php Error Handling
mussawir20
 
PDF
Use of Monolog with PHP
Mindfire Solutions
 
PPTX
Handling error & exception in php
Pravasini Sahoo
 
Exceptions in PHP
JanTvrdik
 
Php exceptions
Damian Sromek
 
Errors, Exceptions & Logging (PHP Hants Oct '13)
James Titcumb
 
Elegant Ways of Handling PHP Errors and Exceptions
ZendCon
 
Php Error Handling
mussawir20
 
Use of Monolog with PHP
Mindfire Solutions
 
Handling error & exception in php
Pravasini Sahoo
 
Ad

Similar to PHP - Introduction to PHP Error Handling (20)

PDF
Error Handling In PHP with all Try catch anf various runtime errors
PraveenHegde20
 
PPT
Error reporting in php
Mudasir Syed
 
PPTX
lecture 15.pptx
ITNet
 
PPTX
Error handling
Meherul1234
 
PPTX
Error and Exception Handling in PHP
Arafat Hossan
 
PDF
Object Oriented PHP - PART-2
Jalpesh Vasa
 
PDF
Sending emails through PHP
krishnapriya Tadepalli
 
PDF
Introduction to php exception and error management
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Module-4_WTA_PHP Class & Error Handling
SIVAKUMAR V
 
PDF
Errors, Exceptions & Logging (PHPNW13 Uncon)
James Titcumb
 
PPTX
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
PDF
Types of Error in PHP
Vineet Kumar Saini
 
ODP
PHP Basic
Yoeung Vibol
 
PPTX
Errors
agjmills
 
PPTX
Php debugging
Larry Ball
 
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PPT
Php Ppt
Hema Prasanth
 
PPTX
PHP Basics
Bhaktaraz Bhatta
 
DOC
basic error handling wesite
PutuMahendra Wijaya
 
Error Handling In PHP with all Try catch anf various runtime errors
PraveenHegde20
 
Error reporting in php
Mudasir Syed
 
lecture 15.pptx
ITNet
 
Error handling
Meherul1234
 
Error and Exception Handling in PHP
Arafat Hossan
 
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Sending emails through PHP
krishnapriya Tadepalli
 
Introduction to php exception and error management
baabtra.com - No. 1 supplier of quality freshers
 
Module-4_WTA_PHP Class & Error Handling
SIVAKUMAR V
 
Errors, Exceptions & Logging (PHPNW13 Uncon)
James Titcumb
 
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
Types of Error in PHP
Vineet Kumar Saini
 
PHP Basic
Yoeung Vibol
 
Errors
agjmills
 
Php debugging
Larry Ball
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Php Ppt
Hema Prasanth
 
PHP Basics
Bhaktaraz Bhatta
 
basic error handling wesite
PutuMahendra Wijaya
 

More from Vibrant Technologies & Computers (20)

PPT
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
PPT
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
PPT
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
PPT
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
PPT
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
PPT
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
PPT
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
PPT
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
PPT
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
PPT
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
PPT
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
PPT
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
PPT
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
PPT
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
PPT
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
PPT
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
PPT
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
PPT
SAS - overview of SAS
Vibrant Technologies & Computers
 
PPT
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
PPT
Teradata - Restoring Data
Vibrant Technologies & Computers
 
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
 
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
 
SQL- Introduction to MySQL
Vibrant Technologies & Computers
 
SQL- Introduction to SQL database
Vibrant Technologies & Computers
 
ITIL - introduction to ITIL
Vibrant Technologies & Computers
 
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
 
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
 
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
 
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
 
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
 
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
 
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
 
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
 
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
 
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
 
Sas - Introduction to working under change management
Vibrant Technologies & Computers
 
SAS - overview of SAS
Vibrant Technologies & Computers
 
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
 
Teradata - Restoring Data
Vibrant Technologies & Computers
 

Recently uploaded (20)

PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
Software Development Company | KodekX
KodekX
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
This slide provides an overview Technology
mineshkharadi333
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 

PHP - Introduction to PHP Error Handling

  • 2. Introduction to PHPIntroduction to PHP Error HandlingError Handling
  • 3. TypesTypes There are 12 unique error types, which can be grouped into 3 main categories: • Informational (Notices) • Actionable (Warnings) • Fatal
  • 4. Informational ErrorsInformational Errors • Harmless problem, and can be avoided through use of explicit programming. e.g. use of an undefined variable, defining a string without quotes, etc.
  • 5. Actionable ErrorsActionable Errors • Indicate that something clearly wrong has happened and that action should be taken. e.g. file not present, database not available, missing function arguments, etc.
  • 6. Fatal ErrorsFatal Errors • Something so terrible has happened during execution of your script that further processing simply cannot continue. e.g. parsing error, calling an undefined function, etc.
  • 7. Identifying ErrorsIdentifying Errors E_STRICT Feature or behaviour is depreciated (PHP5). E_NOTICE Detection of a situation that could indicate a problem, but might be normal. E_USER_NOTICE User triggered notice. E_WARNING Actionable error occurred during execution. E_USER_WARNING User triggered warning. E_COMPILE_WARNING Error occurred during script compilation (unusual) E_CORE_WARNING Error during initialization of the PHP engine. E_ERROR Unrecoverable error in PHP code execution. E_USER_ERROR User triggered fatal error. E_COMPILE_ERROR Critical error occurred while trying to read script. E_CORE_ERROR Occurs if PHP engine cannot startup/etc. E_PARSE Raised during compilation in response to syntax error notice warning fatal
  • 8. Causing errorsCausing errors • It is possible to cause PHP at any point in your script. trigger_error($msg,$type); e.g. … if (!$db_conn) { trigger_error(‘db conn failed’,E_USER_ERROR); } …
  • 9. PHP Error HandlingPHP Error Handling
  • 10. Customizing ErrorCustomizing Error HandlingHandling • Generally, how PHP handles errors is defined by various constants in the installation (php.ini). • There are several things you can control in your scripts however..
  • 11. Set error reportingSet error reporting settingssettings error_reporting($level) This function can be used to control which errors are displayed, and which are simply ignored. The effect only lasts for the duration of the execution of your script.
  • 12. Set error reporting settingsSet error reporting settings <?php // Turn off all error reporting error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings ...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE error_reporting(E_ALL ^ E_NOTICE); // Report ALL PHP errors error_reporting(E_ALL); ?>
  • 13. Set error reportingSet error reporting settingssettings • Hiding errors is NOT a solution to a problem. • It is useful, however, to hide any errors produced on a live server. • While developing and debugging code, displaying all errors is highly recommended!
  • 14. Suppressing ErrorsSuppressing Errors • The special @ operator can be used to suppress function errors. • Any error produced by the function is suppressed and not displayed by PHP regardless of the error reporting setting.
  • 15. Suppressing ErrorsSuppressing Errors $db = @mysql_connect($h,$u, $p); if (!$db) { trigger_error(‘blah’,E_USER_ ERROR); }
  • 16. Suppressing ErrorsSuppressing Errors $db = @mysql_connect($h,$u,$p); if (!$db) { trigger_error(blah.',E_USER_ERROR ); } $db = @mysql_connect($h,$u,$p); Attempt to connect to database. Suppress error notice if it fails..
  • 17. Suppressing ErrorsSuppressing Errors $db = @mysql_connect($h,$u,$p); if (!$db) { trigger_error(‘blah’,E_USER_ERROR); } Since error is suppressed, it must be handled gracefully somewhere else..
  • 18. Suppressing ErrorsSuppressing Errors • Error suppression is NOT a solution to a problem. • It can be useful to locally define your own error handling mechanisms. • If you suppress any errors, you must check for them yourself elsewhere.
  • 19. Custom Error HandlerCustom Error Handler • You can write your own function to handle PHP errors in any way you want. • You simply need to write a function with appropriate inputs, then register it in your script as the error handler. • The handler function should be able to receive 4 arguments, and return true to indicate it has handled the error…
  • 20. Custom Error HandlerCustom Error Handler function err_handler( $errcode,$errmsg,$file,$lineno) { echo ‘An error has occurred!<br />’; echo “file: $file<br />”; echo “line: $lineno<br />”; echo “Problem: $errmsg”; return true; }
  • 21. Custom Error HandlerCustom Error Handler function err_handler( $errcode,$errmsg,$file,$lineno) { echo ‘An error has occurred!<br />’; echo “file: $file<br />”; echo “line: $lineno<br />”; echo “Problem: $errmsg”; return true; } $errcode,$errmsg,$file,$lineno) { The handler must have 4 inputs.. 1.error code 2.error message 3.file where error occurred 4.line at which error occurred
  • 22. Custom Error HandlerCustom Error Handler function err_handler( $errcode,$errmsg,$file,$lineno) { echo ‘An error has occurred!<br />’; echo “file: $file<br />”; echo “line: $lineno<br />”; echo “Problem: $errmsg”; return true; } echo ‘An error has occurred!<br />’; echo “file: $file<br />”; echo “line: $lineno<br />”; echo “Problem: $errmsg”; Any PHP statements can be executed…
  • 23. Custom Error HandlerCustom Error Handler function err_handler( $errcode,$errmsg,$file,$lineno) { echo ‘An error has occurred!<br />’; echo “file: $file<br />”; echo “line: $lineno<br />”; echo “Problem: $errmsg”; return true; } return true; Return true to let PHP know that the custom error handler has handled the error OK.
  • 24. Custom Error HandlerCustom Error Handler • The function then needs to be registered as your custom error handler: set_error_handler(‘err_handler’); • You can ‘mask’ the custom error handler so it only receives certain types of error. e.g. to register a custom handler just for user triggered errors: set_error_handler(‘err_handler’, E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR);
  • 25. Custom Error HandlerCustom Error Handler • A custom error handler is never passed E_PARSE, E_CORE_ERROR or E_COMPILE_ERROR errors as these are considered too dangerous. • Often used in conjunction with a ‘debug’ flag for neat combination of debug and production code display..
  • 26. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in-mumbai.html

Editor's Notes

  • #9: Outline how you can cause errors yourself..