Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When abort() is preferred over exit()?

Tags:

c++

c

exit

abort

I know the differences between the two. One notable thing is that abort() sends SIGABRT signal, so it may be relevant when your software relies on them. But for a typical application exit() seems to be more safe version of abort()...? Are there any other concerns to use abort() instead of exit()?

like image 773
mip Avatar asked Sep 09 '10 11:09

mip


People also ask

What is the difference between abort and exit?

abort function The difference between exit and abort is that exit allows the C++ runtime termination processing to take place (global object destructors get called). abort terminates the program immediately. The abort function bypasses the normal destruction process for initialized global static objects.

What does abort () do?

In the C Programming Language, the abort function raises the SIGABRT signal, and causes abnormal program termination that returns an implementation defined code indicating unsuccessful termination.

Which key is used to abort or terminate the program?

The correct answer is Esc Key. The escape key of the keyboard is mainly used to cancel the program.

Which is used to disrupt the execution exit assert system abort () asset?

void abort ( void );


1 Answers

Using abort will dump core, if the user has core dumps enabled. So as a rule of thumb, I'd use abort if you're so unsure about what's gone wrong that the only way to get useful information about it is by analysing a core dump.

If you can safely exit from any given point, and don't need the core dump, then exit is a nicer approach.

like image 126
Andy Mortimer Avatar answered Oct 08 '22 11:10

Andy Mortimer