Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!

Monica Shiralkar

Ranch Hand
+ Follow
since Jul 07, 2012
Cows and Likes
Cows
Total received
8
In last 30 days
0
Total given
0
Likes
Total received
18
Received in last 30 days
2
Total given
80
Given in last 30 days
9
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Monica Shiralkar

It is considered a good way to enclose only the required code in try catch ,instead of simple enclosing the entire code in it.What exactly is the reason and drawback with the latter approach ?

Thanks .
13 minutes ago
It calls the uncaught exception in that case.

If we have the code within try catch block , the exception will be caught.

If we do not have the code within try catch block ,although the program will terminate it will still show exception message on the console.

Is that correct ?
4 hours ago
Thanks.Sorry ,I confused that with Autoboxing.

So does that mean that in case of objects of type OptionalInt ,we are not required to do a null check before using it which is often a practice with other objects  ?
5 hours ago

Stephan van Hulst wrote:It makes it explicit that the function might not have an answer. It forces the client to check that a result is present, because the first code snippet will cause a NullPointerException if the client forgets to check the result.



Thanks.Understood that now .
I wonder how was this being handled before Java 1.5 when the wrapper classes like Integer were introduced.
6 hours ago

Junilu Lacar wrote:What "default handler" are you referring to? Java doesn't have a "default handler" as far as I know.

EDIT: Just noticed that this is in the C#/.Net forum -- I don't know if what I said is true for C#, honestly, but I'd imagine it is. (I could be wrong, of course)



In case of Java , I had read that there is a default exception handler method, which is called as a final handler to take care of any exceptions not caught by the thread in the run() method.

6 hours ago
So, C# disallows that at compile time whereas Java gives error at run time.

Is it related to the difference in the way C# and Java handle exceptions ?
7 hours ago

Stephan van Hulst wrote:It's likely that the exception was caught in a higher call frame, but the catch clause was empty. If so, let it be a lesson: NEVER write empty catch clauses.



Thanks. Actually, my question is somewhat different from this.

My question is that if I do not put any try catch block, then :

Expected result is that the default handler will show this error at console before stopping abruptly.

Actual results is that it doesn't do so.

So is the result I am expecting expected to happen ?


7 hours ago
I was working on a code which was not working but was not giving any error message either. I put a try catch block and after that I started seeing the error message as it was going to the catch block. I was thinking that if the code was not having try catch than the default handler would show this exception in the console . But like I said this was not showing up. Is there any case where will not be able to see the error message unless we out try catch block.
Thanks
8 hours ago
While working on C#, I noticed that the below line will not even compile  :


This is different from the case in java as the below line will compile( and later give exception at runtime ).

8 hours ago

Stephan van Hulst wrote:

The second scenario doesn't happen that often. It's usually a sign that the method with the extra parameter does too much and should be split in smaller methods.
 



And what if it is a method from a Java library that we are calling ?
Thanks .
9 hours ago
Thanks.  In the above code ,what is the advantage of the second code over the first one ?
9 hours ago
Thanks. Is returning an integer or a NAN be an example use case whether either a number is returns or null in case of NAN ?
1 day ago