Hi,
In the following example i'm throwing new exception from "try" block.But i havent seen the thrown exception anywhere while running the program.Eventhough there is "Finally" block ,the exception should be thrown and "finally" block should be executed.Here it was not so,because the exception is not thrown.can anyone please help me. please correct me if i'm wrong. -
-
public class Test3{
-
public static void main(String args[]){
-
System.out.println(method());
-
}
-
public static int method(){
-
try{
-
throw new Exception();
-
}
-
catch(Exception e){
-
throw new Exception();
-
}
-
finally{
-
return 3;
-
}
-
}
-
}
-
-
-
-
-Thanks & Regards,
Hamsa
5 5369
Hi,
In the following example i'm throwing new exception from "try" block.But i havent seen the thrown exception anywhere while running the program.Eventhough there is "Finally" block ,the exception should be thrown and "finally" block should be executed.Here it was not so,because the exception is not thrown.can anyone please help me. please correct me if i'm wrong. -
-
public class Test3{
-
public static void main(String args[]){
-
System.out.println(method());
-
}
-
public static int method(){
-
try{
-
throw new Exception();
-
}
-
catch(Exception e){
-
throw new Exception();
-
}
-
finally{
-
return 3;
-
}
-
}
-
}
-
-
-Thanks & Regards,
Hamsa
There's something strange about your catch block there... So tell me, what exactly happenes when a Exception is thrown?
Greetings,
Nepomuk
Hi,
In the following example i'm throwing new exception from "try" block.But i havent seen the thrown exception anywhere while running the program.Eventhough there is "Finally" block ,the exception should be thrown and "finally" block should be executed.Here it was not so,because the exception is not thrown.can anyone please help me. please correct me if i'm wrong. -
-
public class Test3{
-
public static void main(String args[]){
-
System.out.println(method());
-
}
-
public static int method(){
-
try{
-
throw new Exception();
-
}
-
catch(Exception e){
-
throw new Exception();
-
}
-
finally{
-
return 3;
-
}
-
}
-
}
-
-
-
-
-Thanks & Regards,
Hamsa
You have committed a very common mistake that beginners do - returning from a finally block. Since its the last thing to be executed before it returns from the method, the exception thrown , or anything else returned, is lost.
I can't help it but that catch block reminds me of a short stop in a baseball game:
catch the ball and throw it away as fast as possible again.
kind regards,
Jos ;-)
I can't help it but that catch block reminds me of a short stop in a baseball game:
catch the ball and throw it away as fast as possible again.
kind regards,
Jos ;-)
Actually, it's like catching a ball and throwing a different ball away as fast as possible... ^^
Greetings,
Nepomuk
Actually, it's like catching a ball and throwing a different ball away as fast as possible... ^^
Greetings,
Nepomuk
Yep, but in this particular example a 'finally block' comes in and returns 3
before the other party can catch my new ball.
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics
by: arun gunda |
last post by:
I want to throw exception dynamically. This what I want
to do
For example I want to throw System.Net.WebException
exception.
I will know the full exception name at run time, can I
create a...
|
by: Kerri |
last post by:
Hi,
I am new to .NET
In my Error Logic on my Aspx pages when an error happens
it hits my catch statement where I throw an Exception.
My question is :
what is the difference between Thwo...
|
by: Dave |
last post by:
Josuttis states that I may not throw an exception of type exception or of
one of the standard exception types used for language support. Where in the
Standard am I forbidden from "throw...
|
by: TS |
last post by:
i'm wondering if it is preferred practice to throw exception in this
circumstance. I have seen it done like that, but i have also read that you
should try to never throw an exception in...
|
by: z. f. |
last post by:
in vb asp.net page i'm overriding the finalize method in order to make
cleanup.
if i throw exception there it is not seen on the page.
probably because the page has already sent to the client.
is...
|
by: Ryan Liu |
last post by:
Hi,
In the .NET Framework SDK documentation, I can see DataRow.AcceptChanges
method will throw RowNotInTableException exeception.
And in DataTable.AcceptChanges(), the documentation does not...
|
by: Rob Dob |
last post by:
I am trying to set the NullValue within the Column properties of my Dataset
in VS2005. The DataType is a System.DateTime. and when I try and change it
from "(Throw Exception)" I get the following...
|
by: Steve B. |
last post by:
Hi,
I'm wondering how to correctly throw exception within ASP.Net pages.
I've page wich which waits for an "id" parameter in the querystring. I want
to validate this param.
I've wrote this...
|
by: =?Utf-8?B?TVIgRQ==?= |
last post by:
This may seem like a stupid question but in C#:
Say for instance I have a set of SQL processes that I run via
ExecuteReader(). These processes return several pieces of information to the...
|
by: George2 |
last post by:
Hello everyone,
In Bjarne's book, it is mentioned that sort of STL may throw
exception, like sorting elements in a vector.
In what situation will sort throw exception? I can not find a case....
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |