SlideShare a Scribd company logo
Exception
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
Typing Speed
Week

Target Achieved

1

25

20

2

25

21

3

25

20

4

25

24
Jobs Applied
#

Company

Designation

Applied Date

1

Amal info systems
(Mumbai)

Software developer

20.09.2013

Current Status
-

2

-

3

-
EXCEPTION

Saifuwan.t
saisn11@gmail.com
www.facebook.com/saifusn
m
twitter.com/saifu
linkedin.com/in/saifu snm
+91 9995 47 55 71
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
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
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.
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.
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:
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
Set a Top Level Exception Handler
• The set_exception_handler() function sets a
user-defined function to handle all uncaught
exceptions
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.
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();
Example of Exception
<?php
try
{
$num =10;
if ($num < 20)
{
throw new Exception();
}
}
catch(Exception $exception)
{
print "Except!n";
}
Output
Thank you….
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
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

More Related Content

Similar to Exception (20)

PPT
Exception handling
PPTX
exception%20handlingcpp.pptx
PPTX
Exception handling with python class 12.pptx
PPT
Introduction of exception in vb.net
PPT
Java exception
PDF
Exception handling
PDF
Exception handling
PDF
Exception handling basic
PPT
Exceptionhandling
PPTX
Unit2_2.pptx Chapter 2 Introduction to C#
PPTX
JAVA Presenttation topics Programs.pptx
PDF
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
PDF
JAVA UNIT-2 ONE SHOT NOTES_64156529_2025_07_12_10__250712_103642.pdf
PDF
JAVA UNIT-2 ONE SHOT NOTES_64156529_2025_07_12_10__250712_103642.pdf
PDF
B.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & Multithreading
PPTX
Java SE 11 Exception Handling
PPT
Exception handling
PPTX
Exception Hnadling java programming language
PPTX
UNIT-3.pptx Exception Handling and Multithreading
PPT
cpphtp9_Exception handling in c++ .ppt
Exception handling
exception%20handlingcpp.pptx
Exception handling with python class 12.pptx
Introduction of exception in vb.net
Java exception
Exception handling
Exception handling
Exception handling basic
Exceptionhandling
Unit2_2.pptx Chapter 2 Introduction to C#
JAVA Presenttation topics Programs.pptx
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
JAVA UNIT-2 ONE SHOT NOTES_64156529_2025_07_12_10__250712_103642.pdf
JAVA UNIT-2 ONE SHOT NOTES_64156529_2025_07_12_10__250712_103642.pdf
B.Sc. III(VI Sem) Advance Java Unit1: Exception Handling & Multithreading
Java SE 11 Exception Handling
Exception handling
Exception Hnadling java programming language
UNIT-3.pptx Exception Handling and Multithreading
cpphtp9_Exception handling in c++ .ppt
Ad

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server
Ad

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology

Exception

  • 2. 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
  • 4. Jobs Applied # Company Designation Applied Date 1 Amal info systems (Mumbai) Software developer 20.09.2013 Current Status - 2 - 3 -
  • 6. 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
  • 7. 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
  • 8. 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.
  • 9. 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.
  • 10. 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:
  • 11. 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
  • 12. Set a Top Level Exception Handler • The set_exception_handler() function sets a user-defined function to handle all uncaught exceptions
  • 13. 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.
  • 14. 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();
  • 15. Example of Exception <?php try { $num =10; if ($num < 20) { throw new Exception(); } } catch(Exception $exception) { print "Except!n"; }
  • 18. 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
  • 19. 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