---
title: "Catch Multiple Exceptions"
url: "https://blog.beyondthecloud.dev/tips/catch-multiple-exceptions"
category: "Apex"
tags: "debugging"
published: "2024-02-03"
---

# Catch Multiple Exceptions

Did you know that Exceptions can be chained?

You can chain exception catch!

Did you know that Exceptions can be chained?

```apex
try {
    // do some stuff
} catch (Exception a) {
    // logic after A exception
} catch (Exception b) {
    // logic after B exception
}
```

It can be useful if you want to implement different strategies depending on a thrown exception:

```apex
try {
    Example.doSomethingRisky();
} catch (NullPointerException nullProblem) {
    Helper.callSystemAdmin();
} catch (DmlException insertProblem) {
    System.debug('It\'s not a big deal!');
}
```

It also works with custom exceptions:

```apex
try {
    Example.doSomethingRisky();
} catch (MyQueueStackException customException) {
    System.enqueueJob(new EmergencyQueueable());
} catch (LastHopeException hopeException) {
    GodClass.sendForHelp();
}
```
