If you use std::logic_error exception in your code, in what case do you use it for?
std::logic_errorDefines a type of object to be thrown as exception. It reports errors that are a consequence of faulty logic within the program such as violating logical preconditions or class invariants and may be preventable.
We know that the exception class has two derived classes: logic_error and runtime_error. logic_error has four derived classes: domain_error, invalid_argument, length_error and out_of_range.
std::logic_errorThis class defines the type of objects thrown as exceptions to report errors in the internal logical of the program, such as violation of logical preconditions or class invariants. These errors are presumably detectable before the program executes.
logic_error
is the base for these exceptions:
domain_error
, invalid_argument
, length_error
, out_of_range
.
Those are all logical errors: Somethings wrong with the input such that the output would be illogical. So I'd say you usually don't need to use it directly, since those four cover any logic errors I can think of. But those give you an idea of what the category is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With