How to handle exceptions in JavaScript?
user
Use the try-catch-finally block:

1. **try:** Enclose the code that may throw an exception.
2. **catch:** Define a block that handles a specific exception type. The exception object is accessible within this block.
3. **finally:** Optional block that always executes, regardless of whether an exception is thrown or caught.

Example:
```javascript
try {
    // Code that may throw an exception
} catch (error) {
    // Handle the exception
} finally {
    // Optional code that always executes
}
```
assistant