• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

Error in finally() block.

#1
Hello Friends,

In try...catch...finally... block ... what happen if error occur in finally() block ?

Please help if anyone of you know. Better if you explain with an example.

Thanks & Regards,
Jaymin Thakkar.
 
#2
Hello Friends,

In try...catch...finally... block ... what happen if error occur in finally() block ?

Please help if anyone of you know. Better if you explain with an example.

Thanks & Regards,
Jaymin Thakkar.
Hi frnd if we get an exception in finally block it will terminate the program abnormally.
 
#4
Hello Friends,

In try...catch...finally... block ... what happen if error occur in finally() block ?

Please help if anyone of you know. Better if you explain with an example.

Thanks & Regards,
Jaymin Thakkar.
nothnig will happen . finally block is used to close the db connections and files etc... so , there is no relation between try , catch and finally . U can do debug it manually.

hop my answer is helpful for u !
 
#5
nothnig will happen . finally block is used to close the db connections and files etc... so , there is no relation between try , catch and finally . U can do debug it manually.

hop my answer is helpful for u !
well Dear, u r right bt i had tried to write the logic of divide by 0 in finally() block and it'll give an error and program will be terminated.

Thanks & Regards,
Jaymin Thakkar.
 
#6
the best solution is add one more try{} catch(Exception e){
}

inside the finally block, Exception e can catch all type of exceptions

try {
//
}
catch(....Exception)
{
////////
}
finally {
try { }
catch (Exception e)
{
}
}

public class DivideEg
{
public static void main(String...s)
{
int x=10;
int y=0;
try{

}
catch(Exception e){}
finally{
try{
x=x/y;
}
catch(Exception e1)
{
System.out.println("Finally error came");
}
}
}
}
 
#8
Hey,
finally block will only guarantee that control will come there and try to execute each statement.But if any exception will come there then program will terminate from there itself.
 
Top