Skip to content

Handle errors and return the callback without throwing #4

Closed
@mapsam

Description

@mapsam

In #3 we are beginning to add checks for proper parameters and throwing errors if they are unexpected types. Currently we use the following approach:

if (!info[2]->IsFunction()) 
{
    Nan::ThrowTypeError("third arg 'callback' must be a function");
    return;
}

In an asynchronous function, this throws instead of returning an error in the callback, which is a super big benefit of a callback function. To avoid this currently, we can wrap async functions in try/catch statements but that gets a bit clumsy.

How can we better handle errors in the .cpp & Nan side of things so they are returned as errors instead of thrown?

cc @springmeyer @GretaCB

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions