---
schema_version: "1"
id: 273e1b789a84a119be1f8c7432f2fa25e1f4d57b8e27367adb541cecb1e1f314
title: Exception Handling
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_dml_exception_handling.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_exception_handling.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 59a37833d7e633de5f4840534108351de494de0b65f172dcd0aa44075ea69378
---
# 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.

Account a = new Account(Name='Acme');
try {
    insert as user a;
} catch(DmlException e) {
    // Process exception here
}

- **[Database Class Method Result Objects](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_database_result_classes.htm)**
- **[Returned Database Errors](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_database_error.htm)**