Skip to content
This repository was archived by the owner on Nov 22, 2025. It is now read-only.
This repository was archived by the owner on Nov 22, 2025. It is now read-only.

Throw and try/catch #2

@mhulse

Description

@mhulse

Use just throw and try/catch around awaits:

if (this.options.orange == 'orange') {
// Instead of using `writeFile().then()`, use await:
await fs.writeFile(html, 'Hello world!', 'utf8');
let result = await fs.readFile(html, 'utf8');
await fs.unlink(html);
// Resolve this async function with the result:
return result;
} else {
throw new Error(`Orange isn’t orange, it’s ${this.options.orange}!`);

Here's example of just throw:

https://github.com/mhulse/get-tile-url/blob/f79b35889e0ad43fda12053cd1d2a1dcd8ef3b61/index.js#L90

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions