Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Hacer error dentro de `try` no manejado por `catch`

Quiero que los errores específicos que se lanzan dentro del bloque de try no sean manejados por catch(err)

Ejemplo:

 const someFunc = async () => { ... try { ... // This error should not be handled by the catch and go straight to the middleware throw { status: 404, message: "Not Found", }; } catch (error) { throw { status: 500, message: "Something went wrong", reason: error, }; } };

Después de eso, el middleware maneja los errores.

 export const errorHandler: ErrorRequestHandler = (err, req, res, next) => { const { status = 500, message, reason } = err; res.status(status).json({ success: false, message: message || "Something went wrong", reason: reason || undefined, }); };
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si arroja un error dentro de un bloque try , el catch lo atrapará. Lo mejor que puede hacer es verificar en el bloque catch si se arroja el error que no desea capturar y, de ser así, volver a lanzarlo.

 const someFunc = async () => { try { throw { status: 404, message: "Not Found", }; } catch (error) { // If a 404 error is caught, rethrow it. if (error.status === 404) { throw error; } throw { status: 500, message: "Something went wrong", reason: error, }; } };
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!