Status
This class is returned by all HOOPS Solve, Access & Mesh API functions. It encapsulates error information and provides convenient methods to check for success or failure.
A Status object contains an ErrorCode that indicates what type of error occurred (if any). A successful operation returns a Status with NONE.
Status Class
The Status class provides the following functionality:
-
class
Status Status class encapsulating error codes and success checking.
Public Functions
-
explicit
Status(const Vint error) Constructor for Status from error code. Creates a Status object from an error code. If exceptions are enabled and an error occurred, throws a
std::runtime_errorwith the error message.Parameters: error – Error code value
-
operator bool() const Implicit conversion to bool. Allows Status to be used in boolean expressions.
Returns: true if operation succeeded (no error), false if operation failed (has error)
-
bool
hasError() const Check if the Status contains an error.
See Also
isSuccess(),getErrorCode()Returns: true if an error occurred, false if no error
-
bool
isSuccess() const Check if the operation succeeded.
See Also
hasError(),getErrorCode()Returns: true if operation succeeded (no error), false if operation failed (has error)
-
ErrorCode
getErrorCode() const Get the
ErrorCodefrom the Status object.See Also
getErrorMessage(),hasError()Returns: ErrorCode- The error code, orNONEif no error
-
const char *
getErrorMessage() const Get a human-readable error message. Returns a descriptive error message corresponding to the error code. If no error occurred, returns a message indicating success.
See Also
getErrorCode()Returns: const char* - Error message string describing the error
-
explicit
Usage
Checking for Errors
The Status object can be implicitly converted to bool, making error checking simple:
cae::core::InteractionPair pair;
auto status = pair.define(cae::core::EntityType::FACE, cae::core::EntityType::NODE);
if (!status) {
// Error occurred
std::cerr << "Error: " << status.getErrorMessage() << std::endl;
std::cerr << "Error code: " << static_cast<int>(status.getErrorCode()) << std::endl;
}
Alternative approaches:
// Using hasError()
if (status.hasError()) {
// Handle error
}
// Using isSuccess()
if (status.isSuccess()) {
// Continue with success path
}
// Check specific error code
if (status.getErrorCode() == cae::core::ErrorCode::ENUM) {
// Handle ENUM error specifically
}