How can I cause program to crash and print an error message?

I made a class and I need to be able to crash the program and print an error message if a certain condition is met inside the default constructor.

Something like this inside the default constructor:

1
2
3
4
if(condition){
    //crash program
    //print error message explaining why program crashed
}


What would be the most elegant way to do this?
http://www.cplusplus.com/reference/exception/
Pick an exception which seems most appropriate.
What would be the most elegant way to do this?

Set a custom terminate handler function and then throw an exception that isn't caught.

http://www.cplusplus.com/reference/exception/set_terminate/

Personally I wouldn't intentionally cause a program to crash, I'd inform the user why the program has to close and then exit.

http://www.cplusplus.com/reference/cstdlib/exit/
Topic archived. No new replies allowed.