Primitive return value after exception in method

R

Richard Maher

Hi,

I know this is a case of suck-it-and see but I'd like a reference to the
architectural performance description please. (I'm pretty bad at seeding
Google)

if: -

int fred = -1;
try {
fred = someMethod(String blah);
} catch (e) {};

Now before someMethod raised an exception it had set the designated and
referenced RETURN value to say 1, what will the value of fred be?

Cheers Richard Maher

PS. Sorry again for the Java 101 question but too many beers for the
SCJP and for some reason Google does not have an obvious answer.
 
M

Marcel Müller

int fred = -1;
try {
fred = someMethod(String blah);

This is a syntax error.

fred = someMethod("blah");
} catch (e) {};

Now before someMethod raised an exception it had set the designated and
referenced RETURN value to say 1, what will the value of fred be?

If someMethod throws an exception it never returns normally and so fred
never gets assigned anything else but it's initial value -1.

Java does not pass any arguments or return values by reference. Although
the passed values might be references itself. But this makes no
difference here. Fred is never changed by the call to someMethod if
someMethod throws, regardless of its return type.

The story changes only if you pass a reference type to someMethod and
someMethod make changes to this instance before the exception is thrown.


Marcel
 
A

Arne Vajhøj

This is a syntax error.

fred = someMethod("blah");

I think Richard knows that but just messed up when typing in the
question.
If someMethod throws an exception it never returns normally and so fred
never gets assigned anything else but it's initial value -1.

Java does not pass any arguments or return values by reference. Although
the passed values might be references itself. But this makes no
difference here. Fred is never changed by the call to someMethod if
someMethod throws, regardless of its return type.

I don't even think that this (for the return value) is particular
Java specific.

It must be somewhere between "by definition" and "in practice always"
that variable = functioncall only assigns to variable after
functioncall is completed without exception for imperative
languages.

Arne
 
M

Marcel Müller

I don't even think that this (for the return value) is particular
Java specific.

Well, it is not only Java specific, of course. But there are languages
that can return values in case of exceptions. E.g. ABAP comes into my mind.


Marcel
 
R

Robert Klemme

Well, it is not only Java specific, of course. But there are languages
that can return values in case of exceptions. E.g. ABAP comes into my mind.

One can pass values back to the caller in this situation even in Java -
albeit not via return value. All you need to do is to pass an object
reference into the method and modify the state of that object before you
throw the exception.

Kind regards

robert
 
A

Arne Vajhøj

One can pass values back to the caller in this situation even in Java -
albeit not via return value. All you need to do is to pass an object
reference into the method and modify the state of that object before you
throw the exception.

Including and int array with one element.

Arne
 
R

Richard Maher

On 9/8/2013 4:12 PM, lipska the kat wrote:
n
why in the name of sanity would anyone want to rely in any way on a
value 'returned' from a method that has thrown an exception?

I don't recall ANYONE except YOU introducing the "rely" terminology.

Personally I'm chasing down a few bugs and got useful advice from
technically competent people like Patricia that ruled out some of the
more crazy options I was considering.
 
R

Robert Klemme

On 02/09/13 07:34, Robert Klemme wrote:
I've just read this thread and frankly I'm surprised that apparently
experienced developers are apparently suggesting that this sort of thing
is even attempted.

Where do you see that?

Cheers

robert
 
R

Richard Maher

Why else would you care what the return value from a method that throws
an exception is. If you are not interested in it then why bother to
concern yourself with it in the first place, it's pretty simple really.

Why would anyone not think like you? Good Point.
If you want to see some value the use a debug statement or wrap it in
the exception.

Examining anything other than the exception in an exceptional situation
doesn't compute.


How interesting.

Dear lipska the pussy

**** off!

Yours Sincerely Richard Maher

Ps. How long would you like to go on dip-shit?
 
R

Richard Maher

You have no idea you wanker.

However, in deference to other readers of this group I suggest we take
this offline. Or are you a coward as well as a loud mouth prick.
Sorry? If you're going to call me out can I at least have the Lat:Lng to
the bike sheds? And what does your Mother look like?
 
R

Robert Klemme

Where do I see what?

That "experienced developers are apparently suggesting that this sort of
thing is even attempted".

We're discussing language behavior in this thread. I do not see that
someone is seriously suggesting to actually do that and return values
even in case of an exception. That's why I asked.

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top