Creating Custom Events

What is the best practice for handling errors in custom event listeners?
element.addEventListener('customAction', function(e) {
  try {
    const { data } = e.detail;
    processData(data);
  } catch (error) {
    const errorEvent = new CustomEvent('error:customAction', {
      bubbles: true,
      detail: { originalEvent: e, error }
    });
    element.dispatchEvent(errorEvent);
  }
});
Next Question (10/20)