Experience Salesforce

Exceptional Handling in APEX

What You’ll Learn

  • What Is Exception 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 Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
Rakshabandhan Sale