Closed
Description
- Implement
handler
function inlibsyclinterface/helper
as discussed in Improving exception handling and logging inlibsyclinterface
#677.
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
Assignees
Labels
No labels