{"id":19353227,"url":"https://github.com/JairusSW/try-as","last_synced_at":"2025-07-23T15:07:15.417Z","repository":{"id":240331930,"uuid":"802264139","full_name":"JairusSW/try-as","owner":"JairusSW","description":"Exception Handling for AssemblyScript","archived":false,"fork":false,"pushed_at":"2025-07-02T18:17:28.000Z","size":529,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-19T08:24:22.601Z","etag":null,"topics":["assemblyscript","catching","error","exception","handling","safe"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JairusSW.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"zenodo":null},"funding":{"github":["JairusSW"]}},"created_at":"2024-05-17T21:14:39.000Z","updated_at":"2025-07-02T18:17:31.000Z","dependencies_parsed_at":"2024-05-18T04:26:47.883Z","dependency_job_id":"4d8acf36-a05a-4a0e-aec1-3fb2a2b5e823","html_url":"https://github.com/JairusSW/try-as","commit_stats":null,"previous_names":["jairussw/as-try","jairussw/try-as"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JairusSW/try-as","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JairusSW%2Ftry-as","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JairusSW%2Ftry-as/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JairusSW%2Ftry-as/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JairusSW%2Ftry-as/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JairusSW","download_url":"https://codeload.github.com/JairusSW/try-as/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JairusSW%2Ftry-as/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266699678,"owners_count":23970541,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assemblyscript","catching","error","exception","handling","safe"],"created_at":"2024-11-10T04:41:58.169Z","updated_at":"2025-07-23T15:07:15.406Z","avatar_url":"https://github.com/JairusSW.png","language":"TypeScript","funding_links":["https://github.com/sponsors/JairusSW"],"categories":["Packages"],"sub_categories":["Utility"],"readme":"\u003ch5 align=\"center\"\u003e\n  \u003cpre\u003e\n\u003cspan style=\"font-size: 0.8em;\"\u003e████████ ██████  ██    ██        █████  ███████ \n   ██    ██   ██  ██  ██        ██   ██ ██      \n   ██    ██████    ████   █████ ███████ ███████ \n   ██    ██   ██    ██          ██   ██      ██ \n   ██    ██   ██    ██          ██   ██ ███████ \u003c/span\u003e\n    AssemblyScript - v0.2.4\n  \u003c/pre\u003e\n\u003c/h5\u003e\n\n## 📚 Contents\n\n- [About](#-about)\n- [Installation](#-installation)\n- [Examples](#-examples)\n- [License](#-license)\n- [Contact](#-contact)\n\n## 📝 About\n\nThis library is an addon for AssemblyScript that brings JavaScript-like exception handling to the language, allowing you to use familiar `try/catch` syntax with a custom state management system. This allows AssemblyScript developers to write more readable, maintainable code, while retaining the performance benefits of WebAssembly.\n\n## 💾 Installation\n\n```bash\nnpm install try-as\n```\n\nAdd the `--transform` to your `asc` command (e.g. in package.json)\n\n```bash\n--transform try-as/transform\n```\n\nAlternatively, add it to your `asconfig.json`\n\n```json\n{\n  // ...\n  \"options\": { \"transform\": [\"try-as/transform\"] }\n}\n```\n\n**NOTE: Make sure to load `try-as/transform` last!**\n\nIf you'd like to see the code that the transform generates, run the build step with `DEBUG=true`\n\n## 🪄 Usage\n\nThis library does all the work behind-the-scenes, so you, the developer, can use the classic `try/catch/finally` syntax with no changes!\n\n```js\ntry {\n  abort(\"Failed to execute!\");\n  console.log(\"This should not execute\");\n} catch (e) {\n  console.log(\"Got an error: \" + e.toString());\n} finally {\n  console.log(\"Gracefully shutting down...\");\n  process.exit(0);\n}\n```\n\n## 🔍 Examples\n\n### ✅ Type-safe Error Handling\n\n```js\nimport { JSON } from \"json-as\";\nimport { Exception, ExceptionType } from \"try-as\";\n\ntry {\n  // something dangerous\n} catch (e) {\n  const err = e as Exception; // Notice we cast to Exception\n  if (err.type == ExceptionType.Throw) {\n    console.log(\"Throw: \" + err.toString());\n  } else if (err.type == ExceptionType.Abort) {\n    console.log(\"Abort: \" + err.toString());\n  } else if (err.type == ExceptionType.Unreachable) {\n    console.log(\"Unreachable: \" + err.toString());\n  }\n}\n```\n\n### ⚠️ Working with Custom Errors\n\n```typescript\nimport { Exception } from \"try-as\";\n\nclass MyError extends Error {\n  constructor(message: string) {\n    super(message);\n  }\n}\n\ntry {\n  throw new MyError(\"This is my custom error!\");\n} catch (e) {\n  const err = e as Exception;\n\n  if (err.is\u003cMyError\u003e()) {\n    console.log(\"Caught MyError: \" + err.as\u003cMyError\u003e().message);\n  } else {\n    console.log(\"Unknown error type\");\n  }\n}\n```\n\n### 🔁 Re-throwing Errors\n\nSometimes, you want to catch a certain kind of error, handle it, and re-throw it if needed:\n\n```typescript\ntry {\n  // something dangerous\n} catch (e) {\n  const err = e as Exception;\n\n  if (!err.is\u003cMyError\u003e()) {\n    console.log(\"Rethrowing error: \" + err.toString());\n    err.rethrow();\n    // or\n    throw err;\n  }\n\n  console.log(\"Got MyError, but handled it gracefully\");\n}\n```\n\n## 📃 License\n\nThis project is distributed under an open source license. You can view the full license using the following link: [License](./LICENSE)\n\n## 📫 Contact\n\nPlease send all issues to [GitHub Issues](https://github.com/JairusSW/as-json/issues) and to converse, please send me an email at [me@jairus.dev](mailto:me@jairus.dev)\n\n- **Email:** Send me inquiries, questions, or requests at [me@jairus.dev](mailto:me@jairus.dev)\n- **GitHub:** Visit the official GitHub repository [Here](https://github.com/JairusSW/as-json)\n- **Website:** Visit my official website at [jairus.dev](https://jairus.dev/)\n- **Discord:** Converse with me on [My Discord](https://discord.com/users/600700584038760448) or on the [AssemblyScript Discord Server](https://discord.gg/assemblyscript/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJairusSW%2Ftry-as","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJairusSW%2Ftry-as","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJairusSW%2Ftry-as/lists"}