Select the proper exception type based on the error scenario to provide clearer error handling and better debugging experience: 1. Use ValueError (TORCH_CHECK_VALUE) when input parameters have invalid values
Select the proper exception type based on the error scenario to provide clearer error handling and better debugging experience:
Example:
// For invalid parameter values
TORCH_CHECK_VALUE(
at::isFloatingType(count.scalar_type()),
"binomial only supports floating-point dtypes for count, got: ",
count.scalar_type());
// For other input validation
TORCH_CHECK(
indices.is_pinned() == values.is_pinned(),
"memory pinning of indices must match memory pinning of values");
// For internal invariants
TORCH_INTERNAL_ASSERT(r.idx == 0, "Unexpected parser result");
// For C API null checks
PyObject* tuple = PyTuple_New(2);
if (!tuple) {
throw python_error();
}
Using appropriate exception types helps users better understand and handle errors, improves API clarity, and facilitates more effective debugging. Proper error messages that describe the problem and expected behavior enable users to quickly identify and fix issues.
Enter the URL of a public GitHub repository