Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Loop

Name: Anonymous 2007-02-20 1:41

Is it possible to run a do/while loop in java until an exception is thrown? As in:

try {
    Do {
        ***
    } while ("NO EXCEPTION");
} catch (Exception e) {}

Example being that I'm saving a ArrayList and would like to read from that file all items using .add.readObject() without knowing the file length.

Name: Anonymous 2007-02-20 2:51

try {
    Do {
        ***
    } while (true);
} catch (Exception e) {}

That'll do you. Also, write code that doesn't suck in a language that doesn't. You should be able to tell when you hit the EOF and put that into your while loop and smoke it.

Name: Anonymous 2007-02-20 5:05

>>2, also use for (;;) { ... } for infinite looping, it's simpler.

Also, exceptions are glorified gotos. People managed to turn "Goto considered harmful" into "Exceptions considered best practice", when they are pretty much the same. The only difference between exceptions and goto is you get automatic if (shit_happened) goto fuckfuckfuck; .

Name: Anonymous 2007-02-20 7:10

>>1

If you do that, you are not a master programmer.  In fact, you are an idiot.  Test for a proper condition in your while, or break out of the middle of the loop if you must.  Remember-- you aren't the only person who gets to throw exceptions in your code.  The runtime can too.

Name: Anonymous 2007-02-20 12:38

ABUSE OF EXCEPTIONS FAILS
listen to >>4

Name: Anonymous 2007-02-20 22:00 ID:SnM4iC8M

>>1

Yes you can.  No, you shouldn't.  And, for what it's worth, it's an extremely rare file format that doesn't include the size somewhere, and it's probably a pretty crappy file format too.  Serialize your data better.  Determinism is your friend.

Name: Anonymous 2007-02-21 14:36 ID:BBPJG4oM

>>3
>>4
LISTEN TO THESE MANS

even goto respects scope to a huge degree in fact.

Name: Anonymous 2009-01-14 15:23

is programming gay?

Name: Anonymous 2010-06-25 14:50

WARNING: NECRO POST

Name: Anonymous 2011-01-31 21:34

<-- check em dubz

Name: Anonymous 2011-02-03 0:03

Name: tray 2012-03-15 16:15

hey ya all, guten tag!

Name: Sgt.KabuԗꚂkiman䉖歹 2012-05-28 22:48

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List