<p>This question comes on the heels of the question asked <a href="https://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marke">here</a>.</p>

<p>The email that comes from our web server comes from an IP address that is different than that for the Exchange server. Is this okay if the SPF and Domain keys are setup properly?</p>

[{'answer_id': 32793, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': '<p>It\'s frowned upon for <em>normal</em> exits.  If "not everything is going according to plan", then System.exit is fine.</p>\n\n<p>Update:  I should add that I assume your \'1\' has meaning that is documented somewhere.</p>\n'}, {'answer_id': 32804, 'author': 'Philip Reynolds', 'author_id': 1087, 'author_profile': 'https://Stackoverflow.com/users/1087', 'pm_score': 1, 'selected': False, 'text': '<p>It can be dangerous / problematic in web servlet environments also. </p>\n\n<p>Throwing an Exception is generally considered the other alternative.</p>\n'}, {'answer_id': 32811, 'author': 'Tim Frey', 'author_id': 1471, 'author_profile': 'https://Stackoverflow.com/users/1471', 'pm_score': 2, 'selected': False, 'text': "<p>Our company's policy is that it's OK (even preferred) to call System.exit(-1), but only in init() methods.  I would definitely think twice before calling it during a program's normal flow.</p>\n"}, {'answer_id': 32817, 'author': 'jjnguy', 'author_id': 2598, 'author_profile': 'https://Stackoverflow.com/users/2598', 'pm_score': 1, 'selected': False, 'text': '<p>Throwing exceptions is the best way to send information about a certain error up and out of the app.</p>\n\n<p>A number doesn\'t tell you as much as:</p>\n\n<pre><code>Exception at thread \'main\': FileNotFoundException "The file \'foo\' doesn\'t exist"\n</code></pre>\n\n<p>(or something close to that)</p>\n'}, {'answer_id': 33007, 'author': 'joev', 'author_id': 3449, 'author_profile': 'https://Stackoverflow.com/users/3449', 'pm_score': 3, 'selected': False, 'text': '<p>I agree with the "<em>throw an Exception</em>" crowd. One reason is that calling System.exit makes your code difficult to use if you want other code to be able to use it. For example, if you find out that your class would be useful from a web app, or some kind of message consuming app, it would be nice to allow those containers the opportunity to deal with the failure somehow. A container may want to retry the operation, decide to log and ignore the problem, send an email to an administrator, etc.</p>\n\n<p>An exception to this would be your <code>main()</code> method; this could trap the Exception, and call <code>System.exit()</code> with some value that can be recognized by the calling process or shell script.</p>\n'}, {'answer_id': 33008, 'author': 'Gio', 'author_id': 3477, 'author_profile': 'https://Stackoverflow.com/users/3477', 'pm_score': 6, 'selected': True, 'text': "<p>The use of <code>System.exit</code> is frowned upon when the 'application' is really a sub-application (e.g. servlet, applet) of a larger Java application (server): in this case the <code>System.exit</code> could stop the JVM and hence also all other sub-applications. In this situation, throwing an appropriate exception, which could be caught and handled by the application framework/server is the best option.</p>\n\n<p>If the java application is really meant to be run as a standalone application, there is nothing wrong with using <code>System.exit</code>. in this case, setting an exit value is probably the easiest (and also most used) way of communicating failure or success to the parent process.</p>\n"}, {'answer_id': 34147, 'author': 'Thomas Lötzer', 'author_id': 3587, 'author_profile': 'https://Stackoverflow.com/users/3587', 'pm_score': 2, 'selected': False, 'text': '<p>I think throwing an exception is what you should do when something goes wrong. This way, if your application is not running as a stand-alone app the caller can react to it and has some information about what went wrong. It is also easier for debugging purposes because you as well get a better idea about what went wrong when you see a stack trace.</p>\n\n<p>One important thing to note is that when the exception reaches the top level and therefore causes the VM to quit the VM returns a return code of 1, therefore outside applications that use the return code see that something went wrong.</p>\n\n<p>The only case where I think System.exit() makes sense is when your app is meant to be called by applications which are not Java and therefore have to use return codes to see if your app worked or not and you want those applications to have a chance to react differently on different things going wrong, i.e. you need different return codes.</p>\n'}, {'answer_id': 19823189, 'author': 'djechlin', 'author_id': 1339987, 'author_profile': 'https://Stackoverflow.com/users/1339987', 'pm_score': 2, 'selected': False, 'text': '<p><code>System.exit()</code> will block, and create a deadlock if the thread that initiated it is used in a shutdown hook.</p>\n'}, {'answer_id': 60826283, 'author': 'Franz D.', 'author_id': 4610114, 'author_profile': 'https://Stackoverflow.com/users/4610114', 'pm_score': 0, 'selected': False, 'text': '<p>I feel impelled to add some salt of mine too. This is a great question that always pops up when I write an application.</p>\n\n<p>As everyone here seems to agree, you should be careful using <code>System.exit()</code>, and if possible, use exceptions. However, <code>System.exit()</code> still seems the only way to return basic informations to the system, and thus required if you want to make your application scriptable. If you don\'t need that, just throw an exception and be done with it.</p>\n\n<p>But if (and only if) your application is single-threaded, then it\'s fine to use it -- it\'s guaranteed that no other stuff is going in, and no resources are open (at least if you consistently use the <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" rel="nofollow noreferrer">try-with-resource</a> idiom, which I\'d highly recommend as it also makes the code cleaner and more compact).</p>\n\n<p>On the other hand, as soon as your application creates any kind of thread that may write resources, System.exit() is a total "no, no", because it can (and, with time, will) corrupt data.</p>\n\n<p>To be able to use a multi-threaded and scripted application and still guarantee the data integrity, my best solution so far is to save any resource-modifying thread you create (for example by consistently using a factory method which adds the thread to the list), and also installing a shutdown hook that cleanly ends each thread by interrupting and joining it. As the shutdown hook is also called by <code>System.exit()</code>, this will guarantee (minus programming errors) that no thread is killed in mid-resource writing.</p>\n\n<p>Oh yes, maybe I shouldn\'t even mention it, but: never, EVER, use that horrible <code>System.halt()</code> method. It just shoots the VM in the head and doesn\'t call any shutdown hook.</p>\n'}]
['https://Stackoverflow.com/questions/32803', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2535/']