reid from https://github.com/michuanhaohao/reid-strong-baseline
zhangmeng
2020-01-11 bdf3ad71583fb4ef100d3819ecdae8fd9f70083e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
 
#include <exception>
#include <string>
#include <utility>
 
namespace torch {
namespace data {
 
/// An exception thrown when a DataLoader's worker thread throws an exception,
/// which is caught. A `WorkerException` stores an `exception_ptr` to the
/// original exception thrown in the worker thread.
struct WorkerException : public std::exception {
  /// Constructs a `WorkerException` from an `exception_ptr`.
  explicit WorkerException(std::exception_ptr original)
      : 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();
  }
 
  /// The original exception thrown in the worker thread.
  std::exception_ptr original_exception;
 
  /// This exception's message (not the original exception's message).
  std::string message;
};
 
} // namespace data
} // namespace torch