web based programming - php error and exception handling
TRANSCRIPT
![Page 1: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/1.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, Dwarka Institutional Area, New Delhi-75 Affiliated G.G.S.IP.U, Delhi
By: Shweta Bhardwaj
WEB BASED PROGRAMMING
PAPER ID: 20313
![Page 2: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/2.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
PHP Error and
Exception Handling
![Page 3: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/3.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
• Error handling is the process of catching errors raised by your program and then taking appropriate action. If you would handle errors properly then it may lead to many unforeseen consequences.
• Its very simple in PHP to handle an errors.
![Page 4: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/4.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
Returning errors from functions
• Php in built functions return false when error occurs.
• When a function returns false we can print error message using DIE() function.
The die() function prints a message and exits the current script.
![Page 5: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/5.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
SYNTAX
• die(message)
Message Required. Specifies the message or status
number to write before exiting the script. The status number will not be written to the output.
![Page 6: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/6.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
Example
• <?php$site = "http://www.w3schools.com/";
fopen($site,"r")or die("Unable to connect to $site");?>
![Page 7: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/7.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75
<?php if(!file_exists("/tmp/test.txt")) { die("File not found"); } else { $file=fopen("/tmp/test.txt","r"); print "Opend file sucessfully"; } // Test of the code here. ?>
![Page 8: WEB BASED PROGRAMMING - PHP Error and Exception Handling](https://reader035.vdocuments.us/reader035/viewer/2022070509/589b82161a28ab8e5b8b5f75/html5/thumbnails/8.jpg)
TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, Dwarka Institutional Area, New Delhi-75