ServiceNow
Workflows

IT Workflows
Employee Workflows
Customer Workflows
Creator Workflows

IT Workflows
We offer workflows that can transform IT into a fully-fledged growth engine. Take advantage of the benefits of operational flexibility by increasing workforce adaptability...
Read More

Employee Workflows
Make employee experiences more integrated and engaging with ServiceNow Employee Workflows. Motivate your staff by making it simple for them to obtain what they require when they require it...
Read More

Customer Workflows
We connect clients, front-line agents, middle and back-office staff on a single ServiceNow platform with ServiceNow Customer Workflows using digital processes to scale customer operations...
Read More

Creator Workflows
With a low-code platform, you can quickly create digital workflow apps. Scale quickly across the organization to build natural, linked experiences that users enjoy...
Read More

Solutions
ServiceNow Solutions

IT Service Management
IT Operations Management
IT Asset Management
Governance, Risk, and Compliance
Security Operations

HR Service Delivery
Customer Service Management
Field Service Management
Integration Hub

IT Service Management
IT service management includes all the ServiceNow services and processes that ensure end to end...
Read More

IT Operations Management
ServiceNow ITOM consists of a set of modules in ServiceNow to manage the operations...
Read More

IT Asset Management
It is the set of business practices to manage the lifecycle of various assets in IT like software assets...
Read More

Governance, Risk, and Compliance
Almost every aspect of the business is driven by governance, risk, and compliance...
Read More

Security Operation
To minimize risk, ServiceNow SecOps allows you to immediately identify, prioritize, and respond to threats...
Read More

HR Service Deliver
With ServiceNow HRSD, you can increase company productivity and provide your employees...
Read More

Customer Service Management
Proactively solve problems and take actions to rectify common requests more efficiently with ServiceNow...
Read More

Field Service Management
ServiceNow Field Service Management enables you to efficiently and safely manage field service activity...
Read More

Integration Hub
For the fastest time to value, lowest TCO, and ease of use with zero learning curve for all ServiceNow developers...
Read More

Digital Transformation
Digital Transformation

DevOps
Robotic process automation
User Experience Design

DevOps
Devops includes the set of practices that automates the IT operations and accelerate the delivery...
Read More

Robotic process automationt
We help organizations to integrate different techniques like machine learning and artificial...
Read More

User Experience Design
User experience design is the creation of the effective flow between users and software...
Read More

Product Engineering
Product Engineering

IT Consulting
New Application development
Product testing & QA
Re-engineering & Migration
Support & maintenance

IT Consulting
We help Companies to Better their IT infrastructure and to Implement various IT strategies. Alignment of all the services to boost the overall performance...
Read More

New Application development
We are an IT service provider company using high-value business processes and technical stacks to build digital products...
Read More

Product testing & QA
We help clients to deliver quality products and services. Skilled Quality Assurance Team to perform a series...
Read More

Re-engineering & Migration
Re-Engineering and Migration is the concept of Comparing the Existing business model to the desired model...
Read More

Support & maintenance
We provide a range of support and maintenance services to our clients in the form of version upgrades, post-project support...
Read More

Case Study: Exception Handling In PHP

  • By Aelum consulting
  • August 20, 2021
  • 703 Views

What is an Exception?

An exception is an unwanted event in the program that interrupts the normal flow of the instructions. It is the unexpected outcome of the program.  The major difference between the error and exception is that the exception can be handled by the program, unlike error.

Exception Handling in PHP

Exception handling is the process of handling the exception (run time errors) to induce the normal flow of the code execution. This is the set of actions we take to handle the unwanted behavior of the code. The main goal is to execute the program without any unexpected behavior and outcome of the code.

When an exception occurs in the program, It proceeds generally using these steps:

  • The current code state is saved.
  • The code implementation will switch to a custom exception handler function
  • Then the handler resumes the execution from the saved code state, terminates the script execution / continues the execution from a different location in the code.

Need of Exception Handling in PHP

PHP provides different functionalities in exception handling. It can handle various runtime errors such as IOException, SQLException, ClassNotFoundException, and arithmetic exceptions.

The following keywords are used when we use exception handling in PHP- Try, catch, throw, finally.

  • Try: It is the block of code in which an exception is present. This piece of code raises the exception. Try block should have a catch or finally block. It contains more than one catch block too. 
  • Throw: The throw keyword is used to symbolize the occurrence of a PHP exception Then we try to find a catch statement to handle this exception.
  • Catch:  This is the block of code that is executed when the try block throws an exception. It is responsible for handling the exception in the try block. It is always used with the try block.
  • Finally: The PHP 5.5 version introduced the “finally” statement in PHP. The “finally” block can be used after a catch block or in place of catch blocks. “Finally “ term means that it will be executed no matter the exception is thrown or not. It generally executes the necessary parts of the program. We use it for many purposes like closing the files, closing the open databases connections, etc.

The Basic syntax which we use when handle the exceptions using try and catch is given below.

Exception Handling In PHP

Multiple Exceptions– Multiple exceptions use multiple try-catch blocks for the implementation and execution of the code. It is used when you want to show the customized message or you wanted to perform some unique operation when the exception is thrown.

In the single program, multiple exceptions can be there like arithmetic exceptions, IO exceptions. We will help you to understand the concept of Multiple exceptions firstly by flowchart representation and then by executing the program. 

Flowchart to Describe the working of Multiple Exceptions

Working of Multiple Exception Handling In PHP

Now here is an example for the multiple exceptions using the program.

We will implement the code that divides a number by the number in the denominator.

We have the chance to get the two types of exceptions by dividing the number by zero or by dividing the number by a negative number. 

We can work with the multiple cases of exceptions 

The code below shows the implementation.

Here we are writing the code when we divide a number by the denominator there are two chances of exceptions one is by dividing it to zero or by a negative number. In the program, we are using multiple catches to solve the exceptions.

Using multiple try-catch with multiple exception types

PHP supports the use of more than one nested catch block to handle their thrown exceptions. This provides us the permission to alter our code based on the type of exception thrown. This is useful for customizing how you display an error message. We can handle different types of exceptions using the catch blocks.

The syntax is given below:

flowchart

Use of  try-catch-finally

Introduced in PHP version 5.5, Sometimes we can also use a “finally” section. Finally is useful in many cases it is not just limited to exception handling, it is used to perform the necessary tasks, and in the cases where the execution is independent of exceptions. 

The “finally”  block is always used when the try-catch block exits. It ensures that finally block is executed in any situation.

Example for using try-catch-finally:

 

flowchart

    Flowchart to tell you how this program works.

Flowchart to tell how this program works

 Explanation of the working of flowchart

 Firstly we check If the exception occurs or not and if occurs it will be handled by the catch block. There are two chances-

  1. The exception will be handled
  2. The exception will not be handled.

If the exception is handled by the catch block then the “finally’’ block will be executed too.

If the exception is not handled, then also the “finally” block will be executed itself

Conclusion of Exception Handling in PHP

The concept of exception is almost similar in all the languages. Exception Handling ensures the normal execution of the programs and we can handle it using try, catch, throw, and finally keywords in PHP.

Thanks For Reading
Read More on Aelum Blogs

Author: Rati Kumari Jha
Designation: Technical Content Writer