Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: What is the appropriate use for the std::logic_error exception?

Tags:

c++

exception

If you use std::logic_error exception in your code, in what case do you use it for?

like image 608
sivabudh Avatar asked Feb 24 '10 22:02

sivabudh


People also ask

What does std :: Logic_error mean?

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.

Which of these is are the exception classes derived from Logic_error?

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.

What is std logic error C++?

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.


1 Answers

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.

like image 64
GManNickG Avatar answered Oct 23 '22 12:10

GManNickG