Skip to content

Async function throws error in try catch without interruption #1272

@robincodex

Description

@robincodex

typescript-to-lua version: 1.4.4

exmaple:

const delay = async () => {
    return new Promise<void>((resolve) => {
        GameRules.GetGameModeEntity().SetContextThink(
            'delay',
            () => {
                resolve();
                return undefined;
            },
            3
        );
    });
};

const foo = async () => {
    await delay();
    throw new Error('foo error');
};

const run = async () => {
    try {
        await foo();
        print('foo after');
    } catch (err) {
        print('catch err:', err);
    }
};
run();

output:

catch err:	Error: foo error
foo after

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions