Newer Version Available

This content describes an older version of this product. View Latest

Exception Handling

DML statements return run-time exceptions if something went wrong in the database during the execution of the 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.

1Account a = new Account(Name='Acme');
2try {
3    insert a;
4} catch(DmlException e) {
5    // Process exception here
6}