Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Typing Speed Week Target Achieved 1 25 20 2 25 21 3 25 20 4 25 24
  3. 3. Jobs Applied # Company Designation Applied Date 1 Amal info systems (Mumbai) Software developer 20.09.2013 Current Status - 2 - 3 -
  4. 4. EXCEPTION Saifuwan.t saisn11@gmail.com www.facebook.com/saifusn m twitter.com/saifu linkedin.com/in/saifu snm +91 9995 47 55 71
  5. 5. EXCEPTION  Exception handling is used to change the normal flow of the code execution if a specified error condition occurs. This condition is called an exception.  Exceptions are objects, created (or “thrown”) when an error occurs  Exceptions can be handled at different points in a script’s execution, and different types of exceptions can be handled by separate portions of a script’s code  All unhandled exceptions are fatal  Exceptions can be thrown from the __construct method on failure  Exceptions change the flow of the application
  6. 6. Different error handling methods • • • • • Basic use of Exceptions Creating a custom exception handler Multiple exceptions Re-throwing an exception Setting a top level exception handler
  7. 7. Basic Use of Exceptions When an exception is thrown, the code following it will not be executed, and PHP will try to find the matching "catch" block.
  8. 8. Creating a Custom Exception Class • Creating a custom exception handler is quite simple. We simply create a special class with functions that can be called when an exception occurs in PHP. The class must be an extension of the exception class.
  9. 9. Multiple Exceptions It is possible to use several if..else blocks, a switch, or nest multiple exceptions. These exceptions can use different exception classes and return different error messages:
  10. 10. Re-throwing Exceptions A script should hide system errors from users. System errors may be important for the coder, but is of no interest to the user. To make things easier for the user you can re-throw the exception with a user friendly message
  11. 11. Set a Top Level Exception Handler • The set_exception_handler() function sets a user-defined function to handle all uncaught exceptions
  12. 12. Try, throw and catch Try - A function using an exception should be in a "try" block. If the exception does not trigger, the code will continue as normal. However if the exception triggers, an exception is "thrown". Throw - This is how you trigger an exception. Each "throw" must have at least one "catch". Catch - - A "catch" block retrieves an exception and creates an object containing the exception information.
  13. 13. The Basic Exception Class exceptions are objects that must be direct or indirect instances of the Exception base class. For eg: class Exception { // The error message associated with this exception protected $message = ’Unknown Exception’; // The error code associated with this exception protected $code = 0; // The pathname of the file where the exception occurred protected $file; // The line of the file where the exception occurred protected $line; // Constructor function __construct ($message = null, $code = 0); // Returns the message final function getMessage(); // Returns the error code final function getCode(); // Returns the file name final function getFile(); // Returns the file line final function getLine(); // Returns an execution backtrace as an array final function getTrace();
  14. 14. Example of Exception <?php try { $num =10; if ($num < 20) { throw new Exception(); } } catch(Exception $exception) { print "Except!n"; }
  15. 15. Output
  16. 16. Thank you….
  17. 17. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  18. 18. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550