exit

How to run code before program exit? [duplicate]

我只是一个虾纸丫 提交于 2019-11-27 03:19:26
This question already has an answer here: Capture console exit C# 10 answers I have a little console C# program like Class Program { static void main(string args[]) { } } Now I want to do something after main() exit. I tried to write a deconstructor for Class Program, but it never get hit. Does anybody know how to do it. Thanks a lot Try the ProcessExit event of AppDomain : using System; class Test { static void Main(string[] args) { AppDomain.CurrentDomain.ProcessExit += new EventHandler (OnProcessExit); // Do something here } static void OnProcessExit (object sender, EventArgs e) { Console

Is there a way to write a bash function which aborts the whole execution, no matter how it is called?

天涯浪子 提交于 2019-11-27 03:00:27
I was using "exit 1" statement in my bash functions to terminate the whole script and it worked fine: function func() { echo "Goodbye" exit 1 } echo "Function call will abort" func echo "This will never be printed" But then I realized that it doesn't do the work when called like: res=$(func) I understand that I created a subshell and "exit 1" aborts that subshell and not the primary one.... But is there a way to write a function which aborts the whole execution, no matter how it is called? I just need to get the real return value (echoed by the function). What you could do, is register the top

What is the command to exit a Console application in C#?

我怕爱的太早我们不能终老 提交于 2019-11-27 02:54:38
What is the command in C# for exit a Console Application? You can use Environment.Exit(0); and Application.Exit Environment.Exit(0) is cleaner . Several options, by order of most appropriate way: Return an int from the Program.Main method Throw an exception and don't handle it anywhere (use for unexpected error situations) To force termination elsewhere, System.Environment.Exit ( not portable! see below ) Edited 9/2013 to improve readability Returning with a specific exit code: As Servy points out in the comments, you can declare Main with an int return type and return an error code that way.

What is the difference between exit() and abort()?

纵饮孤独 提交于 2019-11-27 02:35:20
In C and C++, what is the difference between exit() and abort() ? I am trying to end my program after an error (not an exception). abort() exits your program without calling functions registered using atexit() first, and without calling objects' destructors first. exit() does both before exiting your program. It does not call destructors for automatic objects though. So A a; void test() { static A b; A c; exit(0); } Will destruct a and b properly, but will not call destructors of c . abort() wouldn't call destructors of neither objects. As this is unfortunate, the C++ Standard describes an

Difference between return and exit in Bash functions

浪子不回头ぞ 提交于 2019-11-27 02:21:06
What is the difference between the return and exit statement in Bash functions with respect to exit codes? Diego Sevilla From man bash on return [n] ; Causes a function to stop executing and return the value specified by n to its caller. If n is omitted, the return status is that of the last command executed in the function body. ... on exit [n] : Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap on EXIT is executed before the shell terminates. EDIT: As per your edit of the question, regarding exit codes, return has

How will _Exit behave in a C++ program?

限于喜欢 提交于 2019-11-27 02:15:56
问题 C99 offers the _Exit function, which exits "immediately", although it does may close file descriptors. Unix/POSIX extends this behavior by mandating the closing of all fd's without flushing (and offers the synonym _exit). Will these functions call destructors for static objects when called from a C++ program? Does the C++ standard make any guarantees about _Exit ? (Inspired by this question; I suddenly wondered what happens in the typical fork - exec - _exit idiom in C++.) 回答1: It simply

Exiting batch with `EXIT /B X` where X>=1 acts as if command completed successfully when using && or || operators between batch calls

允我心安 提交于 2019-11-27 01:51:01
问题 I'm trying to chain a series of .bat files using the EXIT /B X command to return success or failure and && and || for conditional running of the next .bat (e.g. a.bat && b.bat ). Regardless of whether I call EXIT /B 0 or anything else to end a.bat, a.bat && b.bat will call b.bat afterward. My understanding is that EXIT /B 0 should set ERRORLEVEL=0 , which is success, so the && should continue. The counterpoint to this is that calling EXIT /B 1 should set ERRORLEVEL=1 which is failure, so the

Android - Confirm app exit with toast

人盡茶涼 提交于 2019-11-27 01:41:12
问题 I'm new to Android development and I want it so when the user presses the back button on the main activity, a toast message appears with a "confirm exit by pressing the back button again" message. How would I do this? This is what I have so far: @Override public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); Toast s = Toast.makeText(getBaseContext(), "Press back again to exit", Toast.LENGTH_LONG); s.show(); wait(); public boolean onBackPressed() { finish(); }

exit android application programmatically

牧云@^-^@ 提交于 2019-11-27 01:29:39
问题 I have two activities, the first is a splash activity. I would like to know how to exit the application from the second activity to the homepage. I've used this method it works BUT it takes to the launcher. public void AppExit() { this.finish(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } 回答1: Whenever you wish to exit all open activities, you should press a button which

Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?

我的未来我决定 提交于 2019-11-27 00:40:11
The docs say that calling sys.exit() raises a SystemExit exception which can be caught in outer levels. I have a situation in which I want to definitively and unquestionably exit from inside a test case, however the unittest module catches SystemExit and prevents the exit. This is normally great, but the specific situation I am trying to handle is one where our test framework has detected that it is configured to point to a non-test database. In this case I want to exit and prevent any further tests from being run. Of course since unittest traps the SystemExit and continues happily on it's way