SlideShare a Scribd company logo
PHP Exception handler Throwing and catching exceptions is the good way to make sure your application doesn't do stuff it isn't supposed to do and leaving your application broken.
ISSUE ?? When you're working on a web application, this might not be your desired action because you don't want to let your visitor know your application is broken. Instead, you want to handle exceptions your own way, by bubbling exceptions upwards so you can manage exceptions in one place.
Bubbling exceptions ?? Bubbling exceptions means that you check in your code fragment for an exception (in your try statement) and throwing this upwards (in your catch statement).
Exmp. class MMMException extends Exception {} function sendMailers() { try { // send MMM Mailers } catch (MMMException $e) { throw new MMMException($e->getMessage()); log_message('error', 'Some happen.'); } return $this->xmlrpc->send_error_message('001', 'error'); }
So Finally ... You can create your exception handler method to handle each exception on it's own and perform a specific action. In this case you might want to log these exceptions, but when accessing databases, files or webservices you might want to send out an e-mail to the administrator or developers.
Wrapping it up ... Throwing a default ‘Exception’ is bad practice if you ever want to act on that specific error scenario. Without extending the Exception class you can only catch all or none. New exceptions can be thrown in catch blocks. That way it’s possible to prevent unexpected exception types to cross certain application design boundaries. Once class design involves abstract classes or interfaces it is wise to design exception structures as well and organize them in similar layers of abstraction.
Sample code Let's start right to see sample code to emulate exception (Everyone loves code, right?)
At any point where a developer needs to handle the possibility of an exception being thrown he needs to know:- What Exceptions can I expect? What Exceptions do I plan to catch?
The Basic Exception Let’s assume a XMLRPC-based web-service client class used to submit order-data to a supplier’s web-service. The web-service client throws an exception if required configuration parameters are missing. The actual XMLRPC Client object will be initialized when the first webservice method is called.
The Basic Exception try { $client->submitOrder($order); } catch (Exception $e) { // We need to act on this asap... $AppError->register_error($e); // Redirect to application error page $Redirect->error($e); }
The Basic Exception In case of a configuration error a redirect is performed to an application-error page. And (just an example) some mechanism is triggered that starts to bug a (or all) developers that there’s a problem that needs immediate attention.
Knowing what to catch class WsXMLRPC_ClientException extends Exception {} class WsXMLRPC_ClientConfigurationException extends WsXMLRPC_ClientException{} class WsXMLRPC_ClientConnectionException extends WsXMLRPC_ClientException{}
class WsXMLRPC_Client { // ... private function initXMLRPC_Client() { if (!is_null($this->XMLRPC_Client)) { return; } if (!$this->config->searchAgent) { throw new WsXMLRPC_ClientConfigurationException( 'Configuration error' ); } try { $this->XMLRPC_Client = new XMLRPC_Client( $this->config->searchAgent,  array('exceptions'=>1) ); } catch (XMLRPC_Fault $e) { throw new WsXMLRPC_ClientConnectionException( 'Cannot load SearchAgent: '.$this->config->searchAgent ); } } }
Sample Code ... $client = new WsXMLRPC_Client($config); try { $client->submitOrder($order); } catch (WsXMLRPC_ClientConnectionException $e) { // store the order in a queue to be processed later $Order->queue(); $Redirect->Page('OrderQueued', $order); } catch (Exception $e) { // Catch everything, also WsXMLRPC_ClientConfigurationException // We need to act on this asap... $AppError->register_error($e); // Redirect to application error page $Redirect->error($e); }
Exception in batch job  do { $retry = false; try { $bool = // return true if send mail  if ($bool === false) { throw new MailSendException(); } } catch (MailSendException $e) { if (Not found SMTP Detail) { echo "$mailerid SMTP Details" ."ERROR.\n"; } else { if (Connection timeout error) { echo "connection time out error" ."$mailerid.\n"; } else { echo "Unknown error attempting to access " ."$mailerid.\n"; } } $retry = true; } } while ($retry);
[email_address]
Ad

Recommended

Triggers-Sequences-SQL
Triggers-Sequences-SQL
Patrick Seery
 
Exception handling in asp.net
Exception handling in asp.net
LearningTech
 
Dynamic Web Pages Ch 3 V1.0
Dynamic Web Pages Ch 3 V1.0
Cathie101
 
Exception handling in asp.net
Exception handling in asp.net
Neelesh Shukla
 
Exception handling in ASP .NET
Exception handling in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
 
Handling error & exception in php
Handling error & exception in php
Pravasini Sahoo
 
Exceptions in c++
Exceptions in c++
Kuntal Bhowmick
 
javaScript tutorial
javaScript tutorial
Zachary Powell
 
Exception handling
Exception handling
Prafull Johri
 
Exception handling
Exception handling
Iblesoft
 
Exception handling and templates
Exception handling and templates
farhan amjad
 
Exception Handling in C++
Exception Handling in C++
Deepak Tathe
 
e computer notes - Creating views
e computer notes - Creating views
ecomputernotes
 
C++ ala
C++ ala
Megha Patel
 
Angular Mini-Challenges
Angular Mini-Challenges
Jose Mendez
 
exception handling in cpp
exception handling in cpp
gourav kottawar
 
Form Validation
Form Validation
Graeme Smith
 
Exception handling c++
Exception handling c++
Jayant Dalvi
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
 
Error handling in XPages
Error handling in XPages
dominion
 
Rethrowing exception- JAVA
Rethrowing exception- JAVA
Rajan Shah
 
JAVA SWITCH STATEMENT
JAVA SWITCH STATEMENT
Rhythm Suiwal
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
Exception handling
Exception handling
Pranali Chaudhari
 
Exception handling
Exception handling
pooja kumari
 
Declarative presentations UIKonf
Declarative presentations UIKonf
Nataliya Patsovska
 
Cramp websockets
Cramp websockets
Antônio Roberto Silva
 
Exceptions ref
Exceptions ref
. .
 
Avangate transition to_saa_s_-_whitepaper
Avangate transition to_saa_s_-_whitepaper
2Checkout
 
Surf Pitch Deck
Surf Pitch Deck
sarahcornwell
 

More Related Content

What's hot (20)

Exception handling
Exception handling
Prafull Johri
 
Exception handling
Exception handling
Iblesoft
 
Exception handling and templates
Exception handling and templates
farhan amjad
 
Exception Handling in C++
Exception Handling in C++
Deepak Tathe
 
e computer notes - Creating views
e computer notes - Creating views
ecomputernotes
 
C++ ala
C++ ala
Megha Patel
 
Angular Mini-Challenges
Angular Mini-Challenges
Jose Mendez
 
exception handling in cpp
exception handling in cpp
gourav kottawar
 
Form Validation
Form Validation
Graeme Smith
 
Exception handling c++
Exception handling c++
Jayant Dalvi
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
 
Error handling in XPages
Error handling in XPages
dominion
 
Rethrowing exception- JAVA
Rethrowing exception- JAVA
Rajan Shah
 
JAVA SWITCH STATEMENT
JAVA SWITCH STATEMENT
Rhythm Suiwal
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
Exception handling
Exception handling
Pranali Chaudhari
 
Exception handling
Exception handling
pooja kumari
 
Declarative presentations UIKonf
Declarative presentations UIKonf
Nataliya Patsovska
 
Cramp websockets
Cramp websockets
Antônio Roberto Silva
 
Exceptions ref
Exceptions ref
. .
 
Exception handling
Exception handling
Iblesoft
 
Exception handling and templates
Exception handling and templates
farhan amjad
 
Exception Handling in C++
Exception Handling in C++
Deepak Tathe
 
e computer notes - Creating views
e computer notes - Creating views
ecomputernotes
 
Angular Mini-Challenges
Angular Mini-Challenges
Jose Mendez
 
exception handling in cpp
exception handling in cpp
gourav kottawar
 
Exception handling c++
Exception handling c++
Jayant Dalvi
 
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
 
Error handling in XPages
Error handling in XPages
dominion
 
Rethrowing exception- JAVA
Rethrowing exception- JAVA
Rajan Shah
 
JAVA SWITCH STATEMENT
JAVA SWITCH STATEMENT
Rhythm Suiwal
 
Logical Expressions in C/C++. Mistakes Made by Professionals
Logical Expressions in C/C++. Mistakes Made by Professionals
PVS-Studio
 
Exception handling
Exception handling
pooja kumari
 
Declarative presentations UIKonf
Declarative presentations UIKonf
Nataliya Patsovska
 
Exceptions ref
Exceptions ref
. .
 

Viewers also liked (14)

Avangate transition to_saa_s_-_whitepaper
Avangate transition to_saa_s_-_whitepaper
2Checkout
 
Surf Pitch Deck
Surf Pitch Deck
sarahcornwell
 
Social Networking Media
Social Networking Media
2Checkout
 
Gesl rainbow plus 13 presentation
Gesl rainbow plus 13 presentation
yunir
 
5 Software Niche Affiliate Success Stories
5 Software Niche Affiliate Success Stories
2Checkout
 
High Performance Web Sites
High Performance Web Sites
Ravi Raj
 
Web Performance Tips
Web Performance Tips
Ravi Raj
 
Web application security
Web application security
Ravi Raj
 
Conversion Rate Optimization
Conversion Rate Optimization
2Checkout
 
Code Review
Code Review
Ravi Raj
 
Is it time to start using HTML 5
Is it time to start using HTML 5
Ravi Raj
 
Character Encoding issue with PHP
Character Encoding issue with PHP
Ravi Raj
 
5 Guaranteed Methods to Increase Your Software Business’ Revenue
5 Guaranteed Methods to Increase Your Software Business’ Revenue
2Checkout
 
How PHP Works ?
How PHP Works ?
Ravi Raj
 
Avangate transition to_saa_s_-_whitepaper
Avangate transition to_saa_s_-_whitepaper
2Checkout
 
Social Networking Media
Social Networking Media
2Checkout
 
Gesl rainbow plus 13 presentation
Gesl rainbow plus 13 presentation
yunir
 
5 Software Niche Affiliate Success Stories
5 Software Niche Affiliate Success Stories
2Checkout
 
High Performance Web Sites
High Performance Web Sites
Ravi Raj
 
Web Performance Tips
Web Performance Tips
Ravi Raj
 
Web application security
Web application security
Ravi Raj
 
Conversion Rate Optimization
Conversion Rate Optimization
2Checkout
 
Code Review
Code Review
Ravi Raj
 
Is it time to start using HTML 5
Is it time to start using HTML 5
Ravi Raj
 
Character Encoding issue with PHP
Character Encoding issue with PHP
Ravi Raj
 
5 Guaranteed Methods to Increase Your Software Business’ Revenue
5 Guaranteed Methods to Increase Your Software Business’ Revenue
2Checkout
 
How PHP Works ?
How PHP Works ?
Ravi Raj
 
Ad

Similar to PHP Exception handler (20)

Php exceptions
Php exceptions
Damian Sromek
 
Effective PHP. Part 6
Effective PHP. Part 6
Vasily Kartashov
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Introduction to php exception and error management
Introduction to php exception and error management
baabtra.com - No. 1 supplier of quality freshers
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and Exceptions
ZendCon
 
Exception
Exception
baabtra.com - No. 1 supplier of quality freshers
 
Nikola Poša "Handling exceptional conditions with grace and style"
Nikola Poša "Handling exceptional conditions with grace and style"
Fwdays
 
Code Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured Exceptions
John Anderson
 
Dealing with not so exceptional exceptions
Dealing with not so exceptional exceptions
Charles Desneuf
 
object oriented programming in PHP & Functions
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
Zend VMにおける例外の実装
Zend VMにおける例外の実装
Yoshio Hanawa
 
Code Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured Exceptions
John Anderson
 
Les exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe comment
Charles Desneuf
 
Zend VMにおける例外の実装
Zend VMにおける例外の実装
Yoshio Hanawa
 
Exceptions irst
Exceptions irst
jkumaranc
 
Coding for Scale and Sanity
Coding for Scale and Sanity
JimKellerES
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Wen-Tien Chang
 
Exceptions in PHP
Exceptions in PHP
JanTvrdik
 
Training material exceptions v1
Training material exceptions v1
Shinu Suresh
 
Object Oriented PHP - PART-2
Object Oriented PHP - PART-2
Jalpesh Vasa
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and Exceptions
ZendCon
 
Nikola Poša "Handling exceptional conditions with grace and style"
Nikola Poša "Handling exceptional conditions with grace and style"
Fwdays
 
Code Fast, Die Young, Throw Structured Exceptions
Code Fast, Die Young, Throw Structured Exceptions
John Anderson
 
Dealing with not so exceptional exceptions
Dealing with not so exceptional exceptions
Charles Desneuf
 
object oriented programming in PHP & Functions
object oriented programming in PHP & Functions
BackiyalakshmiVenkat
 
TDC 2015 - POA - Trilha PHP - Shit Happens
TDC 2015 - POA - Trilha PHP - Shit Happens
Jackson F. de A. Mafra
 
Zend VMにおける例外の実装
Zend VMにおける例外の実装
Yoshio Hanawa
 
Code Fast, die() Early, Throw Structured Exceptions
Code Fast, die() Early, Throw Structured Exceptions
John Anderson
 
Les exceptions, oui, mais pas n'importe comment
Les exceptions, oui, mais pas n'importe comment
Charles Desneuf
 
Zend VMにおける例外の実装
Zend VMにおける例外の実装
Yoshio Hanawa
 
Exceptions irst
Exceptions irst
jkumaranc
 
Coding for Scale and Sanity
Coding for Scale and Sanity
JimKellerES
 
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Exception Handling: Designing Robust Software in Ruby (with presentation note)
Wen-Tien Chang
 
Exceptions in PHP
Exceptions in PHP
JanTvrdik
 
Training material exceptions v1
Training material exceptions v1
Shinu Suresh
 
Ad

Recently uploaded (20)

You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 

PHP Exception handler

  • 1. PHP Exception handler Throwing and catching exceptions is the good way to make sure your application doesn't do stuff it isn't supposed to do and leaving your application broken.
  • 2. ISSUE ?? When you're working on a web application, this might not be your desired action because you don't want to let your visitor know your application is broken. Instead, you want to handle exceptions your own way, by bubbling exceptions upwards so you can manage exceptions in one place.
  • 3. Bubbling exceptions ?? Bubbling exceptions means that you check in your code fragment for an exception (in your try statement) and throwing this upwards (in your catch statement).
  • 4. Exmp. class MMMException extends Exception {} function sendMailers() { try { // send MMM Mailers } catch (MMMException $e) { throw new MMMException($e->getMessage()); log_message('error', 'Some happen.'); } return $this->xmlrpc->send_error_message('001', 'error'); }
  • 5. So Finally ... You can create your exception handler method to handle each exception on it's own and perform a specific action. In this case you might want to log these exceptions, but when accessing databases, files or webservices you might want to send out an e-mail to the administrator or developers.
  • 6. Wrapping it up ... Throwing a default ‘Exception’ is bad practice if you ever want to act on that specific error scenario. Without extending the Exception class you can only catch all or none. New exceptions can be thrown in catch blocks. That way it’s possible to prevent unexpected exception types to cross certain application design boundaries. Once class design involves abstract classes or interfaces it is wise to design exception structures as well and organize them in similar layers of abstraction.
  • 7. Sample code Let's start right to see sample code to emulate exception (Everyone loves code, right?)
  • 8. At any point where a developer needs to handle the possibility of an exception being thrown he needs to know:- What Exceptions can I expect? What Exceptions do I plan to catch?
  • 9. The Basic Exception Let’s assume a XMLRPC-based web-service client class used to submit order-data to a supplier’s web-service. The web-service client throws an exception if required configuration parameters are missing. The actual XMLRPC Client object will be initialized when the first webservice method is called.
  • 10. The Basic Exception try { $client->submitOrder($order); } catch (Exception $e) { // We need to act on this asap... $AppError->register_error($e); // Redirect to application error page $Redirect->error($e); }
  • 11. The Basic Exception In case of a configuration error a redirect is performed to an application-error page. And (just an example) some mechanism is triggered that starts to bug a (or all) developers that there’s a problem that needs immediate attention.
  • 12. Knowing what to catch class WsXMLRPC_ClientException extends Exception {} class WsXMLRPC_ClientConfigurationException extends WsXMLRPC_ClientException{} class WsXMLRPC_ClientConnectionException extends WsXMLRPC_ClientException{}
  • 13. class WsXMLRPC_Client { // ... private function initXMLRPC_Client() { if (!is_null($this->XMLRPC_Client)) { return; } if (!$this->config->searchAgent) { throw new WsXMLRPC_ClientConfigurationException( 'Configuration error' ); } try { $this->XMLRPC_Client = new XMLRPC_Client( $this->config->searchAgent, array('exceptions'=>1) ); } catch (XMLRPC_Fault $e) { throw new WsXMLRPC_ClientConnectionException( 'Cannot load SearchAgent: '.$this->config->searchAgent ); } } }
  • 14. Sample Code ... $client = new WsXMLRPC_Client($config); try { $client->submitOrder($order); } catch (WsXMLRPC_ClientConnectionException $e) { // store the order in a queue to be processed later $Order->queue(); $Redirect->Page('OrderQueued', $order); } catch (Exception $e) { // Catch everything, also WsXMLRPC_ClientConfigurationException // We need to act on this asap... $AppError->register_error($e); // Redirect to application error page $Redirect->error($e); }
  • 15. Exception in batch job do { $retry = false; try { $bool = // return true if send mail if ($bool === false) { throw new MailSendException(); } } catch (MailSendException $e) { if (Not found SMTP Detail) { echo "$mailerid SMTP Details" ."ERROR.\n"; } else { if (Connection timeout error) { echo "connection time out error" ."$mailerid.\n"; } else { echo "Unknown error attempting to access " ."$mailerid.\n"; } } $retry = true; } } while ($retry);