PyTorch
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions
Exception.h File Reference
#include <c10/macros/Macros.h>
#include <c10/util/Deprecated.h>
#include <c10/util/StringUtil.h>
#include <c10/util/variant.h>
#include <cstddef>
#include <exception>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

class  c10::Error
 The primary ATen error class. More...
 
class  c10::Warning
 
class  c10::Warning::UserWarning
 
class  c10::Warning::DeprecationWarning
 
class  c10::WarningHandler
 
class  c10::WarningUtils::WarningHandlerGuard
 
struct  c10::WarningUtils::WarnAlways
 
class  c10::IndexError
 
class  c10::ValueError
 
class  c10::TypeError
 
class  c10::NotImplementedError
 
class  c10::EnforceFiniteError
 
class  c10::OnnxfiBackendSystemError
 
class  c10::LinAlgError
 
class  c10::OutOfMemoryError
 
class  c10::DistBackendError
 

Namespaces

namespace  c10
 
namespace  c10::WarningUtils
 
namespace  c10::detail
 

Macros

#define C10_THROW_ERROR(err_type, msg)
 
#define C10_EXPAND_MSVC_WORKAROUND(x)   x
 
#define C10_UNLIKELY_OR_CONST(e)   C10_UNLIKELY(e)
 
#define TORCH_RETHROW(e, ...)
 
#define TORCH_INTERNAL_ASSERT(cond, ...)
 
#define TORCH_CHECK_WITH(error_t, cond, ...)    TORCH_CHECK_WITH_MSG(error_t, cond, "", __VA_ARGS__)
 
#define TORCH_CHECK_MSG(cond, type, ...)
 
#define TORCH_CHECK_WITH_MSG(error_t, cond, type, ...)
 
#define TORCH_CHECK(cond, ...)
 
#define TORCH_CHECK_IF_NOT_ON_CUDA(cond, ...)   TORCH_CHECK(cond, ##__VA_ARGS__)
 
#define TORCH_INTERNAL_ASSERT_DEBUG_ONLY(...)    C10_EXPAND_MSVC_WORKAROUND(TORCH_INTERNAL_ASSERT(__VA_ARGS__))
 
#define TORCH_CHECK_LINALG(cond, ...)    TORCH_CHECK_WITH_MSG(LinAlgError, cond, "LINALG", __VA_ARGS__)
 
#define TORCH_CHECK_INDEX(cond, ...)    TORCH_CHECK_WITH_MSG(IndexError, cond, "INDEX", __VA_ARGS__)
 
#define TORCH_CHECK_VALUE(cond, ...)    TORCH_CHECK_WITH_MSG(ValueError, cond, "VALUE", __VA_ARGS__)
 
#define TORCH_CHECK_TYPE(cond, ...)    TORCH_CHECK_WITH_MSG(TypeError, cond, "TYPE", __VA_ARGS__)
 
#define TORCH_CHECK_NOT_IMPLEMENTED(cond, ...)    TORCH_CHECK_WITH_MSG(NotImplementedError, cond, "TYPE", __VA_ARGS__)
 
#define WARNING_MESSAGE_STRING(...)   ::c10::str(__VA_ARGS__)
 
#define _TORCH_WARN_WITH(warning_t, ...)
 
#define TORCH_WARN(...)   _TORCH_WARN_WITH(::c10::UserWarning, __VA_ARGS__);
 
#define TORCH_WARN_DEPRECATION(...)    _TORCH_WARN_WITH(::c10::DeprecationWarning, __VA_ARGS__);
 
#define _TORCH_WARN_ONCE(...)
 
#define TORCH_WARN_ONCE(...)
 
#define TORCH_CHECK_ARG(cond, argN, ...)    TORCH_CHECK(cond, "invalid argument ", argN, ": ", __VA_ARGS__)
 
#define AT_ASSERT(...)
 
#define AT_ASSERTM(cond, ...)
 
#define AT_ERROR(...)
 

Typedefs

using c10::UserWarning = Warning::UserWarning
 
using c10::DeprecationWarning = Warning::DeprecationWarning
 

Functions

void c10::warn (const Warning &warning)
 
void c10::WarningUtils::set_warning_handler (WarningHandler *handler) noexcept(true)
 Sets the global warning handler. More...
 
WarningHandler * c10::WarningUtils::get_warning_handler () noexcept(true)
 Gets the global warning handler. More...
 
void c10::WarningUtils::set_warnAlways (bool) noexcept(true)
 The TORCH_WARN_ONCE macro is difficult to test for. More...
 
bool c10::WarningUtils::get_warnAlways (void) noexcept(true)
 
std::string c10::GetExceptionString (const std::exception &e)
 
template<typename... Args>
decltype(auto) c10::detail::torchCheckMsgImpl (const char *, const Args &... args)
 
const char * c10::detail::torchCheckMsgImpl (const char *msg)
 
const char * c10::detail::torchCheckMsgImpl (const char *, const char *args)
 
void c10::detail::torchCheckFail (const char *func, const char *file, uint32_t line, const std::string &msg)
 
void c10::detail::torchCheckFail (const char *func, const char *file, uint32_t line, const char *msg)
 
void c10::detail::torchInternalAssertFail (const char *func, const char *file, uint32_t line, const char *condMsg, const char *userMsg)
 
void c10::detail::torchInternalAssertFail (const char *func, const char *file, uint32_t line, const char *condMsg, ::c10::detail::CompileTimeEmptyString)
 
void c10::detail::torchInternalAssertFail (const char *func, const char *file, uint32_t line, const char *condMsg, const std::string &userMsg)
 
void c10::detail::deprecated_AT_ERROR ()
 
void c10::detail::deprecated_AT_ASSERT ()
 
void c10::detail::deprecated_AT_ASSERTM ()
 

Macro Definition Documentation

◆ _TORCH_WARN_ONCE

#define _TORCH_WARN_ONCE (   ...)
Value:
C10_UNUSED static const auto C10_ANONYMOUS_VARIABLE(torch_warn_once_) = \
[&] { \
TORCH_WARN(__VA_ARGS__); \
return true; \
}()

◆ _TORCH_WARN_WITH

#define _TORCH_WARN_WITH (   warning_t,
  ... 
)
Value:
warning_t(), \
{__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, \
WARNING_MESSAGE_STRING(__VA_ARGS__), \
false));
Definition: Exception.h:116
void warn(const Warning &warning)

◆ AT_ASSERT

#define AT_ASSERT (   ...)
Value:
do { \
::c10::detail::deprecated_AT_ASSERT(); \
C10_EXPAND_MSVC_WORKAROUND(TORCH_INTERNAL_ASSERT(__VA_ARGS__)); \
} while (false)
#define TORCH_INTERNAL_ASSERT(cond,...)
Definition: Exception.h:377

◆ AT_ASSERTM

#define AT_ASSERTM (   cond,
  ... 
)
Value:
do { \
::c10::detail::deprecated_AT_ASSERTM(); \
C10_EXPAND_MSVC_WORKAROUND(TORCH_INTERNAL_ASSERT(cond, __VA_ARGS__)); \
} while (false)

◆ AT_ERROR

#define AT_ERROR (   ...)
Value:
do { \
::c10::detail::deprecated_AT_ERROR(); \
C10_EXPAND_MSVC_WORKAROUND(TORCH_CHECK(false, ::c10::str(__VA_ARGS__))); \
} while (false)
#define TORCH_CHECK(cond,...)
Definition: Exception.h:505

◆ C10_EXPAND_MSVC_WORKAROUND

#define C10_EXPAND_MSVC_WORKAROUND (   x)    x

◆ C10_THROW_ERROR

#define C10_THROW_ERROR (   err_type,
  msg 
)
Value:
throw ::c10::err_type( \
{__func__, __FILE__, static_cast<uint32_t>(__LINE__)}, msg)

◆ C10_UNLIKELY_OR_CONST

#define C10_UNLIKELY_OR_CONST (   e)    C10_UNLIKELY(e)

◆ TORCH_CHECK

#define TORCH_CHECK (   cond,
  ... 
)
Value:
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchCheckFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
TORCH_CHECK_MSG(cond, "", ##__VA_ARGS__)); \
}
#define TORCH_CHECK_MSG(cond, type,...)
Definition: Exception.h:439
#define C10_UNLIKELY_OR_CONST(e)
Definition: Exception.h:326

◆ TORCH_CHECK_ARG

#define TORCH_CHECK_ARG (   cond,
  argN,
  ... 
)     TORCH_CHECK(cond, "invalid argument ", argN, ": ", __VA_ARGS__)

◆ TORCH_CHECK_IF_NOT_ON_CUDA

#define TORCH_CHECK_IF_NOT_ON_CUDA (   cond,
  ... 
)    TORCH_CHECK(cond, ##__VA_ARGS__)

◆ TORCH_CHECK_INDEX

#define TORCH_CHECK_INDEX (   cond,
  ... 
)     TORCH_CHECK_WITH_MSG(IndexError, cond, "INDEX", __VA_ARGS__)

◆ TORCH_CHECK_LINALG

#define TORCH_CHECK_LINALG (   cond,
  ... 
)     TORCH_CHECK_WITH_MSG(LinAlgError, cond, "LINALG", __VA_ARGS__)

◆ TORCH_CHECK_MSG

#define TORCH_CHECK_MSG (   cond,
  type,
  ... 
)
Value:
"Expected " #cond \
" to be true, but got false. " \
"(Could this error message be improved? If so, " \
"please report an enhancement request to PyTorch.)", \
##__VA_ARGS__))
decltype(auto) torchCheckMsgImpl(const char *, const Args &... args)
Definition: Exception.h:424

◆ TORCH_CHECK_NOT_IMPLEMENTED

#define TORCH_CHECK_NOT_IMPLEMENTED (   cond,
  ... 
)     TORCH_CHECK_WITH_MSG(NotImplementedError, cond, "TYPE", __VA_ARGS__)

◆ TORCH_CHECK_TYPE

#define TORCH_CHECK_TYPE (   cond,
  ... 
)     TORCH_CHECK_WITH_MSG(TypeError, cond, "TYPE", __VA_ARGS__)

◆ TORCH_CHECK_VALUE

#define TORCH_CHECK_VALUE (   cond,
  ... 
)     TORCH_CHECK_WITH_MSG(ValueError, cond, "VALUE", __VA_ARGS__)

◆ TORCH_CHECK_WITH

#define TORCH_CHECK_WITH (   error_t,
  cond,
  ... 
)     TORCH_CHECK_WITH_MSG(error_t, cond, "", __VA_ARGS__)

◆ TORCH_CHECK_WITH_MSG

#define TORCH_CHECK_WITH_MSG (   error_t,
  cond,
  type,
  ... 
)
Value:
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
C10_THROW_ERROR(error_t, TORCH_CHECK_MSG(cond, type, __VA_ARGS__)); \
}

◆ TORCH_INTERNAL_ASSERT

#define TORCH_INTERNAL_ASSERT (   cond,
  ... 
)
Value:
if (C10_UNLIKELY_OR_CONST(!(cond))) { \
::c10::detail::torchInternalAssertFail( \
__func__, \
__FILE__, \
static_cast<uint32_t>(__LINE__), \
#cond \
" INTERNAL ASSERT FAILED at " C10_STRINGIZE(__FILE__) ":" C10_STRINGIZE( \
__LINE__) ", please report a bug to PyTorch. ", \
c10::str(__VA_ARGS__)); \
}

◆ TORCH_INTERNAL_ASSERT_DEBUG_ONLY

#define TORCH_INTERNAL_ASSERT_DEBUG_ONLY (   ...)     C10_EXPAND_MSVC_WORKAROUND(TORCH_INTERNAL_ASSERT(__VA_ARGS__))

◆ TORCH_RETHROW

#define TORCH_RETHROW (   e,
  ... 
)
Value:
do { \
e.add_context(::c10::str(__VA_ARGS__)); \
throw; \
} while (false)

◆ TORCH_WARN

#define TORCH_WARN (   ...)    _TORCH_WARN_WITH(::c10::UserWarning, __VA_ARGS__);

◆ TORCH_WARN_DEPRECATION

#define TORCH_WARN_DEPRECATION (   ...)     _TORCH_WARN_WITH(::c10::DeprecationWarning, __VA_ARGS__);

◆ TORCH_WARN_ONCE

#define TORCH_WARN_ONCE (   ...)
Value:
TORCH_WARN(__VA_ARGS__); \
} else { \
_TORCH_WARN_ONCE(__VA_ARGS__); \
}
bool get_warnAlways(void) noexcept(true)

◆ WARNING_MESSAGE_STRING

#define WARNING_MESSAGE_STRING (   ...)    ::c10::str(__VA_ARGS__)