exit

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

蓝咒 提交于 2019-11-26 09:25:35
问题 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

How to handle a SIGTERM

扶醉桌前 提交于 2019-11-26 09:22:41
问题 Is there a way in Java to handle a received SIGTERM? 回答1: Yes, you can register a shutdown hook with Runtime.addShutdownHook(). 回答2: You could add a shutdown hook to do any cleanup. Like this: public class myjava{ public static void main(String[] args){ Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Inside Add Shutdown Hook"); } }); System.out.println("Shut Down Hook Attached."); System.out.println(5/0); //Operating system sends SIGFPE to

Close a WP7 application programmatically? [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-26 08:33:42
问题 Possible Duplicate: Windows Phone 7 close application How do I programmatically close a WP7 application? 回答1: You can always call an exit by doing this at your landing page use this code on click of your application back button: if (NavigationService.CanGoBack) { while (NavigationService.RemoveBackEntry() != null) { NavigationService.RemoveBackEntry(); } } This will remove back entries from the stack, and you will press a back button it will close the application without any exception. 回答2:

Is it OK to call pthread_exit from main?

爷,独闯天下 提交于 2019-11-26 08:27:57
问题 When I call pthread_exit from main , the program never gets to terminate. I expected the program to finish, since I was exiting the program\'s only thread, but it doesn\'t work. It seems hung. #include <stdio.h> #include <stdlib.h> #include <pthread.h> int main(int argc, char *argv[]) { printf(\"-one-\\n\"); pthread_exit(NULL); printf(\"-two-\\n\"); } Process Explorer shows that the (only) thread is in Wait:DelayExecution state. According to pthread_exit documentation: The process shall exit

Android: Capturing the return of an activity

最后都变了- 提交于 2019-11-26 07:57:04
问题 I have a question regarding launching new activities. It boils down to this. I have 3 tabs on a view A) contains gMap activity B) camera activity C) some random text fields. Requirement is that the application runs in Portrait mode. All 3 tabs work as expected w/ the exception of the Camera Preview Surface (B). It is rotated 90 degrees. They only way to make it correct is to set the app to landscape which throws all my tabs around, and is pretty much unworkable. My solution is this : replace

exit() call inside a function which should return a reference

混江龙づ霸主 提交于 2019-11-26 07:49:23
问题 In a library I have a function which searches for a key in a database and return a non-const reference to an object. I want to handle the case in which the key is not found, which is typically caused by a mistake when calling the function. This situation is so bad that the program cannot continue, so I print a message to help to spot the bug and call exit(1) . The problem is with the return statement which will never be executed in this case, but have to be there anyway. If it was a pointer I

WPF Command Line

て烟熏妆下的殇ゞ 提交于 2019-11-26 07:24:50
问题 I am trying to create a WPF application that takes command line arguments. If no arguments are given, the main window should pop up. In cases of some specific command line arguments, code should be run with no GUI and exit when finished. Any suggestions on how this should properly be done would be appreciated. 回答1: First, find this attribute at the top of your App.xaml file and remove it: StartupUri="Window1.xaml" That means that the application won't automatically instantiate your main

How to exit when back button is pressed?

风格不统一 提交于 2019-11-26 07:21:10
问题 When a user presses the back button on an intent, the application should quit. How can I ensure the application quits when the back button is pressed? 回答1: Immediately after you start a new activity, using startActivity , make sure you call finish() so that the current activity is not stacked behind the new one. EDIT With regards to your comment: What you're suggesting is not particularly how the android app flow usually works, and how the users expect it to work. What you can do if you

Checking Bash exit status of several commands efficiently

笑着哭i 提交于 2019-11-26 06:52:59
问题 Is there something similar to pipefail for multiple commands, like a \'try\' statement but within bash. I would like to do something like this: echo \"trying stuff\" try { command1 command2 command3 } And at any point, if any command fails, drop out and echo out the error of that command. I don\'t want to have to do something like: command1 if [ $? -ne 0 ]; then echo \"command1 borked it\" fi command2 if [ $? -ne 0 ]; then echo \"command2 borked it\" fi And so on... or anything like: pipefail

How to exit from Python without traceback?

守給你的承諾、 提交于 2019-11-26 06:13:42
问题 I would like to know how to I exit from Python without having an traceback dump on the output. I still want want to be able to return an error code but I do not want to display the traceback log. I want to be able to exit using exit(number) without trace but in case of an Exception (not an exit) I want the trace. 回答1: You are presumably encountering an exception and the program is exiting because of this (with a traceback). The first thing to do therefore is to catch that exception, before