const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
try {
// Code that may throw an error
const result = someFunction();
res.send(`Result: ${result}`);
} catch (error) {
// Handle the error
console.error('Error:', error.message);
res.status(500).send('Internal Server Error');
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
function someFunction() {
// Function that may throw an error
throw new Error('An error occurred in someFunction');
}