use Exception instead of std exceptions#500
Conversation
There was a problem hiding this comment.
Pull request overview
This PR standardizes error handling across SeQuant by replacing uses of std::runtime_error / std::logic_error / std::invalid_argument / etc. with the project’s custom sequant::Exception, and updates unit tests and Doxygen @throw annotations accordingly.
Changes:
- Replaced standard-library exception types with
sequant::Exceptionacross core, MBPT domain, export, eval backends, and serialization code. - Updated unit tests to assert
Exceptionis thrown instead of STL exception types. - Removed many now-unneeded
<stdexcept>includes and addedexception.hppwhere required.
Reviewed changes
Copilot reviewed 60 out of 60 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_wick.cpp | Update expected thrown type to Exception for deprecated spinfree() mismatch cases. |
| tests/unit/test_utilities.cpp | Update singleton tests to expect/catch sequant::Exception. |
| tests/unit/test_tensor_network.cpp | Update tensor network tests to expect Exception for invalid constructions/connections. |
| tests/unit/test_math.cpp | Update to_rational(NaN) test to expect Exception. |
| tests/unit/test_latex.cpp | Update narrow-string Unicode error tests to expect Exception. |
| tests/unit/test_expr.cpp | Update constant conversion/adjoint tests to expect Exception for unsupported operations. |
| SeQuant/domain/mbpt/vac_av.cpp | Throw Exception for unknown expression types. |
| SeQuant/domain/mbpt/utils.cpp | Throw Exception for unsupported expression/term types. |
| SeQuant/domain/mbpt/spin.cpp | Replace various std::runtime_error throws with Exception for unsupported expression structures. |
| SeQuant/domain/mbpt/op_registry.cpp | Add exception.hpp include and switch registry validation errors to Exception. |
| SeQuant/domain/mbpt/op.hpp | Replace std::logic_error with Exception for unknown vacuum type. |
| SeQuant/domain/mbpt/op.cpp | Replace std::runtime_error / std::invalid_argument with Exception in vacuum/context validation. |
| SeQuant/domain/mbpt/biorthogonalization.cpp | Update throws and @throw docs to use Exception. |
| SeQuant/core/wick.impl.hpp | Throw Exception for invalid nested Sum structure in input. |
| SeQuant/core/wick.hpp | Replace throws and @throw docs with Exception. |
| SeQuant/core/utility/singleton.hpp | Include exception.hpp and throw Exception for singleton lifecycle errors. |
| SeQuant/core/utility/indices.hpp | Throw Exception for unsupported expression types in get_unique_indices. |
| SeQuant/core/utility/expr.hpp | Throw Exception for unimplemented composite replacements. |
| SeQuant/core/utility/expr.cpp | Throw Exception for invalid expression types during transforms/popping. |
| SeQuant/core/tensor_network/v3.hpp | Replace std::invalid_argument with Exception for edge/tensor validation. |
| SeQuant/core/tensor_network/v3.cpp | Throw Exception for unsupported recursive protoindices. |
| SeQuant/core/tensor_network/v2.hpp | Replace std::logic_error / std::invalid_argument with Exception for connection/tensor validation. |
| SeQuant/core/tensor_network/v2.cpp | Throw Exception for unsupported recursive protoindices. |
| SeQuant/core/tensor_network/v1.hpp | Replace std::logic_error with Exception for invalid connections / non-tensor inputs. |
| SeQuant/core/tensor_network/v1.cpp | Throw Exception for unsupported recursive protoindices. |
| SeQuant/core/tensor_canonicalizer.hpp | Update @throw docs to reference Exception. |
| SeQuant/core/tensor_canonicalizer.cpp | Throw Exception when canonicalizer is not registered. |
| SeQuant/core/space.hpp | Make IndexSpace::bad_key derive from Exception. |
| SeQuant/core/space.cpp | Throw Exception when index space registry is unavailable. |
| SeQuant/core/runtime.hpp | Include exception.hpp and throw Exception on invalid thread count. |
| SeQuant/core/rational.hpp | Throw Exception for NaN/Inf and rationalization failures. |
| SeQuant/core/op.hpp | Replace std::logic_error / std::invalid_argument with Exception for unsupported vacua/args. |
| SeQuant/core/io/serialization/v1/serialize.cpp | Throw Exception for unsupported expr types in serializer. |
| SeQuant/core/io/serialization/v1/ast_conversions.hpp | Catch Exception instead of std::invalid_argument to wrap index parsing errors. |
| SeQuant/core/io/latex/latex.hpp | Include exception.hpp and update @throw docs to Exception. |
| SeQuant/core/io/latex/latex.cpp | Throw Exception for narrow-char Unicode limitations. |
| SeQuant/core/index_space_registry.hpp | Replace std::invalid_argument throws with Exception across registry validation. |
| SeQuant/core/index.hpp | Replace std::invalid_argument with Exception in index validation. |
| SeQuant/core/hugenholtz.hpp | Replace std::out_of_range with Exception for invalid insertion indices. |
| SeQuant/core/expressions/tensor.hpp | Replace std::logic_error with Exception for invalid tensor rank. |
| SeQuant/core/expressions/expr.hpp | Replace std::invalid_argument with Exception for visiting non-managed expressions; change not_implemented() return type to Exception. |
| SeQuant/core/expressions/expr.cpp | Return Exception from not_implemented() helper. |
| SeQuant/core/expressions/constant.hpp | Replace std::invalid_argument / std::logic_error with Exception in value conversion and arithmetic ops. |
| SeQuant/core/expressions/abstract_tensor.cpp | Replace std::runtime_error with Exception for unsupported expr types. |
| SeQuant/core/export/text_generator.hpp | Replace std::runtime_error with Exception for unsupported expr types. |
| SeQuant/core/export/python_einsum.hpp | Replace multiple std::runtime_error with Exception for unsupported export conditions. |
| SeQuant/core/export/julia_tensor_operations.hpp | Replace std::runtime_error with Exception for unsupported export conditions. |
| SeQuant/core/export/julia_tensor_operations.cpp | Replace std::runtime_error with Exception for missing tags. |
| SeQuant/core/export/julia_tensor_kit.hpp | Include exception.hpp and throw Exception for unsupported creation/representation cases. |
| SeQuant/core/export/julia_itensor.hpp | Include exception.hpp and throw Exception for unsupported creation cases. |
| SeQuant/core/export/itf.hpp | Replace std::runtime_error with Exception across ITF generation constraints. |
| SeQuant/core/export/itf.cpp | Replace std::runtime_error with Exception for missing names/tags. |
| SeQuant/core/export/export.hpp | Replace std::runtime_error with Exception for invalid node/group export scenarios. |
| SeQuant/core/eval/eval_expr.cpp | Replace std::logic_error with Exception for unsupported binarize input. |
| SeQuant/core/eval/backends/tiledarray/result.hpp | Include exception.hpp and throw Exception for invalid rank. |
| SeQuant/core/eval/backends/tapp/tensor.hpp | Include exception.hpp and throw Exception on TAPP errors. |
| SeQuant/core/eval/backends/tapp/result.hpp | Include exception.hpp and throw Exception for invalid rank. |
| SeQuant/core/eval/backends/btas/result.hpp | Include exception.hpp and throw Exception for invalid rank. |
| SeQuant/core/context.hpp | Update @throw docs to reference Exception. |
| SeQuant/core/binary_node.hpp | Replace std::runtime_error with Exception for dereferencing null nodes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include <SeQuant/core/utility/exception.hpp> | ||
| #include <cassert> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <stdexcept> | ||
|
|
There was a problem hiding this comment.
Exception derives from std::exception, but SeQuant/core/utility/exception.hpp only includes <string>. Since this header no longer includes <stdexcept>, compilation can fail when std::exception is not available via transitive includes. Prefer adding #include <exception> to exception.hpp (or include <exception> here before including exception.hpp).
| #include <SeQuant/core/ranges.hpp> | ||
| #include <SeQuant/core/utility/conversion.hpp> | ||
| #include <SeQuant/core/utility/exception.hpp> | ||
|
|
There was a problem hiding this comment.
SeQuant/core/utility/exception.hpp defines sequant::Exception : std::exception but does not include <exception>. This file includes exception.hpp directly (and no longer includes <stdexcept>), so it may fail to compile depending on include order. Prefer adding <exception> to exception.hpp (or include it here).
| throw std::logic_error( | ||
| throw Exception( | ||
| "WickTheorem::compute: spinfree=true supported only for physical " | ||
| "vacuum and for Fermi facuum"); |
There was a problem hiding this comment.
Typo in error message: "facuum" should be "vacuum".
| @@ -376,11 +376,10 @@ class IndexSpace { | |||
|
|
|||
| /// exception type thrown when ancountered unknown/invalid | |||
There was a problem hiding this comment.
Typo in comment: "ancountered" should be "encountered".
No description provided.