Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Could not find or load main class com.mindprod.ensure.Ensure Date: Mon, 13 Jun 2016 22:58:44 -0400 Organization: A noiseless patient Spider Lines: 45 Message-ID: References: <64htlb5ikduodj9qr700ob3tqbulribl5a@4ax.com> <58be2264-bf4a-4da1-a6b2-8501e9daf435@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 14 Jun 2016 02:58:57 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="22e5ab429c5a4bb738666b9c52e40d69"; logging-data="6150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19RJffN7WpBFDIUxLuV4V0E" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 In-Reply-To: Cancel-Lock: sha1:mqASezT6Zkq87kwCT1KYnDOHYqM= Xref: csiph.com comp.lang.java.programmer:34627 On 6/13/2016 9:57 PM, Arne Vajhøj wrote: > On 6/13/2016 8:54 PM, Eric Sosman wrote: >> On 6/13/2016 4:48 PM, Lew wrote: >>> Throwing an exception from 'main' is an antipattern. >> >> Citation? > > I have never seen it catalogued as an anti-pattern. > > And it is very common in various demos and adhoc programs. > > But for a more serious program I would call it very bad for > a GUI program and a code smell warranting further investigation > of UX and exception handling for a console program. What should the main() of a GUI application do if something further down the line throws HeadlessException? Okay, that's a RuntimeException and perhaps we could fix the wording to prohibit only the checked exceptions. But even so: If main() catches an InterruptedException from something further down, what action can main() take that would be better than just letting the IE propagate outward? public static void main(String[] args) { try { // "payload" of main() } catch (InterruptedException ex) { LOGGER.severe("I was interrupted!", ex); Thread.currentThread().interrupt(); // now what? } catch (Exception ex) { LOGGER.severe("I'm thrown for a loss!", ex); // now what? } } What "constructive" or "useful" steps could be taken in the catch blocks that would be "better" than letting main() throw the Exception? In situations where there *is* something better, well sure: Do the better thing. But is it a given that something better is possible? -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM