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

187
Views
el retorno en el bloque catch no se puede ejecutar

Ejemplo básico que arroja un error porque no se especificó tl :

 function allmatches() { SpreadsheetApp.getActive().getSheetByName('data').getRange('A1').setValue(tl) }

Y para saber si hubo algún error en la ejecución en la Web App, agregué un try catch :

 function doGet(e) { const lock = LockService.getDocumentLock(); if (lock.tryLock(360000)) { try { var okgo = e.parameter.okgo; allmatches(); } catch (e) { lock.releaseLock(); return ContentService.createTextOutput('Error!'); } finally { lock.releaseLock(); return ContentService.createTextOutput('Ok!'); } } else { return ContentService.createTextOutput('Timeout!'); } }

Llamo a esta aplicación web de Python y, en teoría, la respuesta debería ser Error! :

 import requests okgo = 'go' webAppsUrl = "https://script.google.com/macros/s/XXXXXXXXXX/exec" url = webAppsUrl + "?okgo=" + okgo web_app_response = requests.get(url) print(web_app_response.text)

Pero la respuesta es:

 Ok!

¿Qué me estoy perdiendo?

Agregue, cuando se ejecuta sin la aplicación web, entra en catch :

 function test() { try { allmatches(); } catch (e) { Logger.log(e) } }

Producción:

 ReferenceError: tl is not defined
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Como puede ver en los siguientes ejemplos, el bloque finally se ejecuta independientemente de si se produce un error o no. Entonces, en el caso de OP ContentService.createTextOutput('Error!'); se reemplaza rápidamente por ContentService.createTextOutput('Ok!'); y el usuario no es consciente del error.

 function testTry() { try { let x = a; console.log(x); } catch(err) { console.log(err); } finally { console.log("finally"); } } 7:52:56 AM Notice Execution started 7:52:58 AM Info [ReferenceError: a is not defined] 7:52:58 AM Info finally 7:52:57 AM Notice Execution completed function testTry() { try { let x = 1; console.log(x); } catch(err) { console.log(err); } finally { console.log("finally"); } } 7:54:37 AM Notice Execution started 7:54:38 AM Info 1 7:54:38 AM Info finally 7:54:38 AM Notice Execution completed
about 4 years ago · Santiago Gelvez 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!