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


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

Re: can't throw

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: can't throw
Date 2012-09-13 23:32 +0200
Message-ID <abf1n5Frh7eU1@mid.individual.net> (permalink)
References (1 earlier) <abaoivFqnh9U1@mid.individual.net> <e726309e-8aa2-45e7-8452-80f1c2ef1b3f@googlegroups.com> <2da52903-55b6-4288-8f95-9799a5ce874c@googlegroups.com> <abccsfF8mgbU1@mid.individual.net> <SL74s.45$4D5.7@newsfe21.iad>

Show all headers | View raw


On 09/13/2012 12:10 AM, Daniel Pitts wrote:
> On 9/12/12 2:24 PM, Robert Klemme wrote:
>> there is no point in throwing from Thread.run()
>> or Runnable.run() other than catastrophic failures (all Errors such as
>> OOM, all RuntimeExceptions which are really programmer mistakes) because
>> you cannot customize handling of exceptions thrown from the run()
>> method: this method is only invoked from class Thread and probably
>> others in the Java standard library itself.
> Actually, you can handle exceptions from a Thread. There is the
> UncaughtExceptionHandler:
> <http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html>
>
>
> Though the only valuable use I have ever seen from this is in logging
> those failures differently than the default output.

Right, I completely forgot about that.  The issue with this is that you 
have far less context than inside method run().  So handling there is 
certainly preferred.

>> Instead, you should be
>> handling exceptions in run() and terminate the thread gracefully (i.e.
>> by returning from run()).
>
> Agreed. If you need some other code to propagate an Exception, you need
> to pass that information along.  Exceptions are meant to unwind the
> stack. For most practical purposes a Thread's run() method really has no
> stack to unwind.  Even if you could throw an Exception from it, where
> would that Exception go? Who's going to deal with it?

... other than the default uncaught exception handler.  Exactly.

Kind regards

	robert

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


Thread

can't throw bob smith <bob@coolfone.comze.com> - 2012-09-11 13:16 -0700
  Re: can't throw markspace <-@.> - 2012-09-11 13:34 -0700
    Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-11 14:15 -0700
  Re: can't throw Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-11 17:02 -0400
    Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-11 14:17 -0700
      Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-11 21:21 -0400
        Re: can't throw Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-09-11 21:59 -0700
          Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-12 09:18 -0700
            Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 19:09 +0200
            Re: can't throw markspace <-@.> - 2012-09-12 10:56 -0700
            Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:36 -0400
              Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-12 18:29 -0700
                Re: can't throw Patricia Shanahan <pats@acm.org> - 2012-09-12 18:34 -0700
                Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 21:37 -0400
                Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 21:54 -0400
          Re: can't throw Jim Janney <jjanney@shell.xmission.com> - 2012-09-12 11:27 -0600
          Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:24 -0400
            Re: can't throw Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2012-09-13 22:20 -0700
              Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 09:49 -0700
                Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-14 20:50 +0200
                Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-14 13:02 -0700
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 14:06 -0700
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-14 13:16 -0700
                Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-14 23:07 +0200
                Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-14 14:28 -0700
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-16 20:04 -0700
        Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:16 -0400
          Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-12 23:15 -0700
        Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-14 17:33 -0500
          Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-16 15:46 +0200
            Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-16 12:17 -0500
              Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-16 22:36 +0200
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-16 20:07 -0700
                Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 07:41 +0200
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-17 09:51 -0700
                Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 21:00 +0200
                Re: can't throw Gene Wirchenko <genew@ocis.net> - 2012-09-17 13:23 -0700
                Re: can't throw Joerg Meier <joergmmeier@arcor.de> - 2012-09-17 18:52 +0200
                Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-17 11:22 -0700
                Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-17 02:52 -0500
                Re: can't throw Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-09-17 02:39 -0500
                Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-17 21:02 +0200
  Re: can't throw markspace <-@.> - 2012-09-11 14:28 -0700
  Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-11 21:14 -0400
    Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:11 -0400
  Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 08:31 +0200
    Re: can't throw bob smith <bob@coolfone.comze.com> - 2012-09-12 11:40 -0700
      Re: can't throw Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-12 15:50 -0400
      Re: can't throw Lew <lewbloch@gmail.com> - 2012-09-12 12:52 -0700
        Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-12 23:24 +0200
          Re: can't throw Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-12 15:10 -0700
            Re: can't throw Robert Klemme <shortcutter@googlemail.com> - 2012-09-13 23:32 +0200
    Re: can't throw Arne Vajhøj <arne@vajhoej.dk> - 2012-09-12 18:06 -0400
  Re: can't throw Roedy Green <see_website@mindprod.com.invalid> - 2012-09-12 20:55 -0700

csiph-web