Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34657

Re: Could not find or load main class com.mindprod.ensure.Ensure

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Could not find or load main class com.mindprod.ensure.Ensure
Date 2016-06-16 01:17 +0000
Organization A noiseless patient Spider
Message-ID <njsumd$r9r$1@dont-email.me> (permalink)
References (2 earlier) <58be2264-bf4a-4da1-a6b2-8501e9daf435@googlegroups.com> <njnkkt$jeh$1@dont-email.me> <njnoa4$17j3$1@gioia.aioe.org> <fc19649e-4f2f-4925-8b3c-fdccab0badc1@googlegroups.com> <njq50f$530$1@dont-email.me>

Show all headers | View raw


On Wed, 15 Jun 2016 02:46:25 +0300, Stanimir Stamenkov wrote:

> Tue, 14 Jun 2016 12:52:15 -0700 (PDT), /Lew/:
> 
>> Reference:
>> When you throw an exception from 'main' you cannot handle it.
> 
> Eric Sosman already gave an example where you can, and you would need to
> handle exceptions from 'main' – when you call main() vs. java calling it
> from the command prompt.  Handling the exception would not be possible
> if you call System.exit() from main(), for comparison.
> 
>> Unhandled exceptions are an antipattern, for example because they lead
>> to bad user experiences and throw program state into lala-land.
> 
> I don't think the later is any argument.  The "lala-land" state should
> be handled by using proper finally, try-with-resources blocks, etc.
> deeper in the implementation of the program.  The main() method could
> not possibly know all details it might need to handle.
> 
> "Bad user experience" is rather subjective and java is reporting the
> exceptions just fine.  If your specific program needs something more –
> then go ahead and implement it.  For extra logging and else I believe
> one should be able to set up JVM, or just main thread shutdown hooks.
> 
> The only case System.exit() would need to be used is when your program
> needs to report many well documented exit codes, which is still specific
> use case.
> 
>> Ergo throwing exceptions from 'main' is an antipattern. Q.E.D.
> 
> Still sounds non-sense to me.

I prefer to use a run() method for running the code as part of a larger 
prcess and reserving the main() method for use only when the class is 
being run as a free-standing process:

public static void run(String args[]) throws Throwable
{
   /* 
      Top-level code that does stuff that the class was written to do
      and throws a Throwable if it fails.
   */
   ....
}

public static void main (String args[])
{
   try
   {
      run(args);
   }
   catch (Throwable t)
   {
      System.err.println("Error: " + t.getMessage());
   } 
}

If the class is part of a program suite with all its components in the 
same jarfile, then I omit the main() method and introduce a 'launcher' 
class. This is declared as the main class in the manifest. Its only job 
is to load the selected top-level program class, call its run() method 
and do any required clean-up after run() has ended. Needless to say, 
these programs are all subclasses of the same superclass and, in some 
cases there may be preliminaries, such as parsing a common configuration 
file, that are best done by the launcher class. 


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Could not find or load main class com.mindprod.ensure.Ensure Roedy Green <inquiry@mindprod.com> - 2016-06-13 06:51 -0700
  Re: Could not find or load main class com.mindprod.ensure.Ensure Roedy Green <inquiry@mindprod.com> - 2016-06-13 07:02 -0700
    Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-13 07:15 -0700
  Re: Could not find or load main class com.mindprod.ensure.Ensure Roedy Green <inquiry@mindprod.com> - 2016-06-13 07:35 -0700
    Re: Could not find or load main class com.mindprod.ensure.Ensure Lew <lewbloch@gmail.com> - 2016-06-13 13:48 -0700
      Re: Could not find or load main class com.mindprod.ensure.Ensure Roedy Green <inquiry@mindprod.com> - 2016-06-13 14:11 -0700
      Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-13 20:54 -0400
        Re: Could not find or load main class com.mindprod.ensure.Ensure Arne Vajhøj <arne@vajhoej.dk> - 2016-06-13 21:57 -0400
          Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-13 22:58 -0400
            Re: Could not find or load main class com.mindprod.ensure.Ensure Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-14 10:33 +0000
              Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-14 04:59 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-14 15:11 +0000
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-14 11:31 -0400
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-14 09:00 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-14 13:18 -0400
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-14 10:38 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Lew <lewbloch@gmail.com> - 2016-06-14 12:55 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-14 13:14 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Lew <lewbloch@gmail.com> - 2016-06-14 13:34 -0700
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Douglas <e.d.programmer@gmail.com> - 2016-06-14 13:58 -0700
          Re: Could not find or load main class com.mindprod.ensure.Ensure Lew <lewbloch@gmail.com> - 2016-06-14 12:52 -0700
            Re: Could not find or load main class com.mindprod.ensure.Ensure Stanimir Stamenkov <s7an10@netscape.net> - 2016-06-15 02:46 +0300
              Re: Could not find or load main class com.mindprod.ensure.Ensure Lew <lewbloch@gmail.com> - 2016-06-15 12:22 -0700
              Re: Could not find or load main class com.mindprod.ensure.Ensure Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-16 01:17 +0000
                Re: Could not find or load main class com.mindprod.ensure.Ensure Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-06-15 21:56 -0400
                Re: Could not find or load main class com.mindprod.ensure.Ensure Martin Gregorie <martin@address-in-sig.invalid> - 2016-06-16 11:01 +0000

csiph-web