Skip to content

Introduce error handler function to be used in places of std::cerr output #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks
Tracked by #677
oleksandr-pavlyk opened this issue Nov 19, 2021 · 0 comments · Fixed by #683
Closed
2 tasks
Tracked by #677

Introduce error handler function to be used in places of std::cerr output #679

oleksandr-pavlyk opened this issue Nov 19, 2021 · 0 comments · Fixed by #683
Assignees

Comments

@oleksandr-pavlyk
Copy link
Contributor

void error_handler(
     const std::exception &e,
     const char *file_name,
     const char *func_name,
     int line_num,
     int level = 0   /* or an enum */
);

void error_handler(
     const std::string &what,
     const char *file_name,
     const char *func_name,
     int line_num,
     int level = 0   /* or an enum */
);
  • Change all functions in dpctl_sycl_plaftorm_interface.cpp to use the handler.

For example,

// function as it is now
__dpctl_give DPCTLSyclPlatformRef
DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef)
{
    auto Platform = unwrap(PRef);
    if (!Platform) {
        std::cerr << "Cannot copy DPCTLSyclPlatformRef as input is a nullptr\n";
        return nullptr;
    }
    try {
        auto CopiedPlatform = new platform(*Platform);
        return wrap(CopiedPlatform);
    } catch (std::bad_alloc const &ba) {
        // \todo log error
        std::cerr << ba.what() << '\n';
        return nullptr;
    }
}

could be changed to:

__dpctl_give DPCTLSyclPlatformRef
DPCTLPlatform_Copy(__dpctl_keep const DPCTLSyclPlatformRef PRef)
{
    auto Platform = unwrap(PRef);
    if (!Platform) {
        error_handler("Cannot copy DPCTLSyclPlatformRef as input is a nullptr", __FILE__, __func__, __LINE__);
        return nullptr;
    }
    try {
        auto CopiedPlatform = new platform(*Platform);
        return wrap(CopiedPlatform);
    } catch (std::exception const &e) {
        error_handler(e, __FILE__, __func__, __LINE__);
        return nullptr;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants