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
¿Por qué no en la captura de la persona que llama () sino en la captura del intento?

Tengo un caso interesante en el que Promise.reject() no está atrapado en .catch() de la persona que llama, sino en try{ }catch{ } .

callDB() llama a una función pg db para realizar una Insert , cuando se produce un error en tiempo de ejecución (violación de clave única), va a .then().catch() :

 const callDB = (param) => { return new Promise((resolve, reject) => { var sql = "...myInsert($1, $2)"; var dataValue = [param.p1, paramp2]; db.any(sql, dataValue) .then ( good => resolve(good), bad => reject(bad) ) // Run-Time Err like unique-key violation caught here, returns a reject. .catch ( dbEr => { return reject(dbEr); }) }); }

f2() , la persona que llama, su callDB().catch() no detecta el reject , pero el try{} catch{tce} :

 async function f2() { try { ... // callDB's reject NOT caught here. const good2 = await callDB(param).catch((e2)=>{ return Promise.reject(e2); }); ... } catch(tce) { // callDB's reject caught here! return Promise.reject(tce); } }

Una función de Azure llama a f2() :

 module.exports = async function f1(context) { try { await f2().then ( good => ... bad => { // Caught here as Expected! ... context.res = {status: 401, body: bad}; } ) .catch ( (e1) => { context.res = {status: 401, body: "never reach e1"}; } ) } catch (etry) { context.res = {status: 401, body: "never reach etry"}; } }

Mis preguntas son:

  1. ¿Por qué el reject de callDB entra en try{} catch{} de f2 ?
  2. ¿Cuál es la diferencia entre .then().catch() y try{} catch{} ?
about 4 years ago · Juan Pablo Isaza
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!