Learn from industry experts! Admin batch starts from 19 Feb.
Hurry up!
Book your slot now!

10

Exceptional Handling in APEX

What Is Exception Handling In Apex?

An exception denotes an error or event that disrupts the normal flow of code execution. Exception disrupts the normal flow of the application hence to keep the application running we use exception handling.

Exception handling is the process of responding to exceptions that appear in the code during its runtime so that the normal flow of the application can be maintained.

Example Of Exceptional Handling In Apex

DML statements return run-time exceptions if something goes wrong in the database during the execution of DML operations. 

You can handle the exceptions in your code by wrapping your DML statements within try-catch blocks. 

The following example includes the insert DML statement inside a try-catch block:

Account a = new Account(Name = 'Acme');
try {
    insert a;
} catch (DmlException e) {
    // Process exception here 
}
salesforce-developer
Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

Book A 15-Minutes Free Career Counselling Today!