{"id":21581545,"url":"https://github.com/thoughtscript/async_error_node_2024","last_synced_at":"2026-04-25T22:33:23.252Z","repository":{"id":245199001,"uuid":"816110101","full_name":"Thoughtscript/async_error_node_2024","owner":"Thoughtscript","description":"Verifying an Article's Suggestion","archived":false,"fork":false,"pushed_at":"2024-06-17T04:42:56.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-24T14:44:59.179Z","etag":null,"topics":["error-handling","node","promises"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Thoughtscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-17T04:14:35.000Z","updated_at":"2024-06-19T23:44:53.000Z","dependencies_parsed_at":"2024-06-20T13:26:41.061Z","dependency_job_id":null,"html_url":"https://github.com/Thoughtscript/async_error_node_2024","commit_stats":null,"previous_names":["thoughtscript/async_error_node_2024"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fasync_error_node_2024","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fasync_error_node_2024/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fasync_error_node_2024/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thoughtscript%2Fasync_error_node_2024/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thoughtscript","download_url":"https://codeload.github.com/Thoughtscript/async_error_node_2024/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244181391,"owners_count":20411605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["error-handling","node","promises"],"created_at":"2024-11-24T14:12:52.736Z","updated_at":"2026-04-25T22:33:18.233Z","avatar_url":"https://github.com/Thoughtscript.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async_error_node\n\n[![](https://img.shields.io/badge/Node-18.13.0-333.svg)](https://nodejs.org/)\n\nReview of Error Handling in Node motivated by [this](https://stackify.com/node-js-error-handling/#h-the-perils-of-async-try-catch) article.\n\nSpecifically:\n\n\u003e \"In summary, if you’re handling async error handling, you should really use the promises catch handler, which will allow you to effectively handle the async errors. But if you’re dealing with synchronous code, the try/catch will do just fine.\"\n\nI think that's not the most accurate, best, precise, or most comprehensive suggestion.\n\nConsider:\n\n1. **Error Handling** *within* an Asynchronous Function, Timeout, Interval, Spawn or Forked Exec. (Will likely be **Synchronous** internal to the Asynchronous Function and will therefore use a `try-catch` block.)\n2. I typically combine a `try-catch` block with a `process.on('uncaughtException', ...)` event listener:\n   \n   ```javascript\n   try {\n        process.on('uncaughtException', exception =\u003e { console.error(`Exception encountered: ${exception}`) })\n\n        //...\n   } catch (ex) {\n        //...\n   } \n   ```\n\n   This acts as a *defacto* `catch` block for any `Error` that bubbles up to the top-level `process` itself. Even Asynchronous ones.\n3. Using a `try-catch` block with `async`-`await` notation is (probably most-)often encountered.\n\n## Topics\n\nRemember:\n\n```JavaScript\n//Same syntactic and semantic functionality\nError()\nnew Error()\n```\n\nRemember that the following is invalid:\n```JavaScript\nT()\n    .then(success =\u003e { console.log(success) }, failure =\u003e { console.log(failure) })\n    .catch(ex =\u003e console.error(`Line 16 - asynch catch(): ${ex.message}`))\n```\nThe `.catch()` chained method will handle `failure`.\n\n## Use\n\n```bash\nnpm i \u0026\u0026 node main.js\n```\n\n```bash\nLine 40 - Exception encountered: Error!\nLine 16 - Exception encountered: Third Async Error!\nLine 21 - asynch catch(): Third Async Error!\nLine 25 - asynch catch(): Fourth Async Error - By Rejection\nLine 47 - Exception encountered: Async Error!\nLine 35 - UncaughtException encountered: Error: Second Async Error!\n```\n\nObserve that lines `54` and `28` are never logged:\n\n* Line `28` is ignored since the prior `.catch()` methods handle Exceptions, Errors, and Rejections.\n* Line `54` is ignored by `setTimeout()` although the `try-catch` block internal to the Timeout is used.\n\n## Resources and Links\n\n1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises\n2. https://stackify.com/node-js-error-handling/#h-the-perils-of-async-try-catch","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtscript%2Fasync_error_node_2024","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtscript%2Fasync_error_node_2024","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtscript%2Fasync_error_node_2024/lists"}