Program Listing for File worker_exception.h¶
↰ Return to documentation for file (torch/csrc/api/include/torch/data/worker_exception.h
)
#pragma once
#include <exception>
#include <string>
#include <utility>
namespace torch::data {
struct WorkerException : public std::exception {
explicit WorkerException(std::exception_ptr original)
// NOLINTNEXTLINE(bugprone-throw-keyword-missing)
: original_exception(std::move(original)),
message("Caught exception in DataLoader worker thread.") {
try {
std::rethrow_exception(original_exception);
} catch (std::exception& e) {
message += " Original message: ";
message += e.what();
}
}
const char* what() const noexcept override {
return message.c_str();
}
std::exception_ptr original_exception;
std::string message;
};
} // namespace torch::data