By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

Exiting program from inside void function

P: 1
Is there any way to exit program directly from inside void function. I want exit the whole program not only the function.
Nov 2 '16 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Exiting from a function is a bad choice. Maybe the function thinks it's time to give up but the calling function may not think the same.

Errors have different meanings based on where you are in the program.

You call the exit() or abort() library but be aware that your C++ objects may not be cleaned up correctly and in a multi-threaded application you can cause a crash on another thread.

Your void function should throw an exception which can be caught by the calling function. That function can decide whether it's OK to continue or not. If not, that function can throw an exception.

So you can see that a series of exceptions are thrown as the error works up the call stack. If appropriate main() can just return.
Nov 3 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.