npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

try-as

v0.2.4

Published

Exception handling for AssemblyScript

Readme

📚 Contents

📝 About

This 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.

💾 Installation

npm install try-as

Add the --transform to your asc command (e.g. in package.json)

--transform try-as/transform

Alternatively, add it to your asconfig.json

{
  // ...
  "options": { "transform": ["try-as/transform"] }
}

NOTE: Make sure to load try-as/transform last!

If you'd like to see the code that the transform generates, run the build step with DEBUG=true

🪄 Usage

This library does all the work behind-the-scenes, so you, the developer, can use the classic try/catch/finally syntax with no changes!

try {
  abort("Failed to execute!");
  console.log("This should not execute");
} catch (e) {
  console.log("Got an error: " + e.toString());
} finally {
  console.log("Gracefully shutting down...");
  process.exit(0);
}

🔍 Examples

✅ Type-safe Error Handling

import { JSON } from "json-as";
import { Exception, ExceptionType } from "try-as";

try {
  // something dangerous
} catch (e) {
  const err = e as Exception; // Notice we cast to Exception
  if (err.type == ExceptionType.Throw) {
    console.log("Throw: " + err.toString());
  } else if (err.type == ExceptionType.Abort) {
    console.log("Abort: " + err.toString());
  } else if (err.type == ExceptionType.Unreachable) {
    console.log("Unreachable: " + err.toString());
  }
}

⚠️ Working with Custom Errors

import { Exception } from "try-as";

class MyError extends Error {
  constructor(message: string) {
    super(message);
  }
}

try {
  throw new MyError("This is my custom error!");
} catch (e) {
  const err = e as Exception;

  if (err.is<MyError>()) {
    console.log("Caught MyError: " + err.as<MyError>().message);
  } else {
    console.log("Unknown error type");
  }
}

🔁 Re-throwing Errors

Sometimes, you want to catch a certain kind of error, handle it, and re-throw it if needed:

try {
  // something dangerous
} catch (e) {
  const err = e as Exception;

  if (!err.is<MyError>()) {
    console.log("Rethrowing error: " + err.toString());
    err.rethrow();
    // or
    throw err;
  }

  console.log("Got MyError, but handled it gracefully");
}

📃 License

This project is distributed under an open source license. You can view the full license using the following link: License

📫 Contact

Please send all issues to GitHub Issues and to converse, please send me an email at [email protected]