try {
    // Code that may throw an exception
    throw new Error('An error occurred.');
} catch (error) {
    // Handle the exception
    console.error(error.message);
}