Return type value if RunTimeException has been thrown and not catched.
Posted
by Alfred
on Stack Overflow
See other posts from Stack Overflow
or by Alfred
Published on 2010-04-14T04:21:51Z
Indexed on
2010/04/14
4:23 UTC
Read the original article
Hit count: 236
I am using Gson to parse Json. What I don't understand what the return type will be if you don't catch the Runtime Exception. I was expecting it to be null
, but it is not null
when evaluating with a simple if
statement.
My code looks something like this:
public X x() {
return gson.fromJson(jsonString, X.class);
}
then from another function I call the function:
public void y() {
final X x = x();
if (x == null) {
System.out.println("x == null")
}
}
I was expecting x to be null, but it isn't because the print statement is not called? What is the value of x? How can if
them. I have my problem by using a catch block in the x()
function and returning null
. But I am just wondering what the value of function x()
is(if any?)? Hopefully I make any sense at all.
© Stack Overflow or respective owner