Try Catch Javascript

try {
  // Code that may throw an error
  let result = riskyFunction();
  console.log(result);
} catch (error) {
  // Code to handle the error
  console.error("An error occurred:", error);
}