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


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

Re: telling the javac that a method doesn't return at all...

From Andreas Leitgeb <avl@auth.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject Re: telling the javac that a method doesn't return at all...
Date 2014-03-05 13:31 +0000
Organization A noiseless patient Spider
Message-ID <slrnlhe9om.rhr.avl@login.logic.tuwien.ac.at> (permalink)
References <slrnlh1gp1.g8j.avl@login.logic.tuwien.ac.at> <53129f56$0$299$14726298@news.sunsite.dk>

Show all headers | View raw


Arne Vajhøj <arne@vajhoej.dk> wrote:
> On 2/28/2014 12:10 PM, Andreas Leitgeb wrote:
>> Suppose I have some "doCleanUpAndExit" method, that in the
>> end either calls System.exit() or throws some Error or custom
>> RuntimeException.
>>
>> I'd like the compiler to *know* that this method cannot possibly
>> return, and that any code following it should be considered
>> as "unreachable" code by the compiler.
>
> I have at a few occasions wished for the same ability.
> Although I typical have needed it to avoid a compiler error.

> Oversimplified example:
>    public int foobar(int v) {
>    	if(v > 0) {
>    	   return v++;
>    	} else {
>    	   System.exit(0);
>    	   return 0; // hmmmm

My advice here is to throw some RuntimeException or Error here.

This may be overly theoretic for System.exit(), but makes more
sense for one's custom com.example.project.StaticUtils.myExit(),
that due to some bug might fail to bail out.

> But to my best knowledge then no such feature exist in Java as of today.

I feared so, but thanks for confirmation.

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


Thread

telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-02-28 17:10 +0000
  Re: telling the javac that a method doesn't return at all... Lew <lewbloch@gmail.com> - 2014-02-28 16:13 -0800
    Re: telling the javac that a method doesn't return at all... Jeff Higgins <jeff@invalid.invalid> - 2014-03-01 09:12 -0500
      Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:06 +0000
  Re: telling the javac that a method doesn't return at all... Roedy Green <see_website@mindprod.com.invalid> - 2014-03-01 01:10 -0800
    Re: telling the javac that a method doesn't return at all... Jeff Higgins <jeff@invalid.invalid> - 2014-03-01 08:44 -0500
  Re: telling the javac that a method doesn't return at all... Arne Vajhøj <arne@vajhoej.dk> - 2014-03-01 22:02 -0500
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:31 +0000
      Re: telling the javac that a method doesn't return at all... Arne Vajhøj <arne@vajhoej.dk> - 2014-03-11 20:11 -0400
        Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-12 10:17 +0000
  Re: telling the javac that a method doesn't return at all... Mike Amling <mamling@chaff.us> - 2014-03-04 13:19 -0600
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-05 13:39 +0000
  Re: telling the javac that a method doesn't return at all... mike.s.schilling@gmail.com - 2014-03-04 19:30 -0800
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-09 14:33 +0000
  Re: telling the javac that a method doesn't return at all... Silvio <silvio@internet.com> - 2014-03-12 14:03 +0100
  Re: telling the javac that a method doesn't return at all... Michal Kleczek <michal_wytnijto@kleczek.org> - 2014-03-19 11:51 +0100
    Re: telling the javac that a method doesn't return at all... Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2014-03-19 12:28 +0000
      Re: telling the javac that a method doesn't return at all... Michal Kleczek <michal_wytnijto@kleczek.org> - 2014-03-23 11:15 +0100

csiph-web