Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Is there a way to stub/intercept a javascript statement 'throw' in vanilla javascript?

We can stub any function or class like this,

class ErrorStub{
        constructor(message){
                // do whatever with 'message'
        }
}
Error = ErrorStub
new Error('This will go to ErrorStub now')

Similar to this, is there any way we can intercept a 'throw' statement. So that whatever exception is thrown across whole website, can be handled in one place?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Wouldn't this satisfy your needs? You would need to listen to the error event, handle it the way you want and return false

function interceptError(exception) {
  // Here you can write code which intercepts before
  // the error gets triggered and printed in the console
  alert(`Exception occured: ${exception.message}`)
}

window.addEventListener("error", function (e) {
  interceptError(e);
  return false;
})

throw new Error('Test exception');

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda