diff --git a/c10/util/Exception.h b/c10/util/Exception.h index e83b65cc5ef..8f942eb39e6 100644 --- a/c10/util/Exception.h +++ b/c10/util/Exception.h @@ -289,6 +289,12 @@ class C10_API OutOfMemoryError : public Error { using Error::Error; }; +// Used for handling syntacitc erros in input arguments. +// They shuld turn into SytnaxError when the cross into Python +class C10_API SyntaxError : public Error { + using Error::Error; +}; + // Base error type for all distributed errors. // These turn into DistError when they cross into Python. class C10_API DistError : public Error { diff --git a/torch/csrc/Exceptions.h b/torch/csrc/Exceptions.h index 7a927c3f03f..4806b4c456c 100644 --- a/torch/csrc/Exceptions.h +++ b/torch/csrc/Exceptions.h @@ -74,6 +74,7 @@ inline void PyErr_SetString(PyObject* type, const std::string& message) { _CATCH_GENERIC_ERROR(TypeError, PyExc_TypeError, retstmnt) \ _CATCH_GENERIC_ERROR( \ NotImplementedError, PyExc_NotImplementedError, retstmnt) \ + _CATCH_GENERIC_ERROR(SyntaxError, PyExc_SyntaxError, retstmnt) \ _CATCH_GENERIC_ERROR(LinAlgError, THPException_LinAlgError, retstmnt) \ _CATCH_GENERIC_ERROR( \ OutOfMemoryError, THPException_OutOfMemoryError, retstmnt) \