Skip to content

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

Closed
@oleksandr-pavlyk

Description

@oleksandr-pavlyk
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;
    }
}

Metadata

Metadata

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