Answer the question
In order to leave comments, you need to log in
What is the meaning of finally?
Java and c# have a try-catch-finally construct. Why is finally needed if
try {
Integer.parseInt("test");
System.out.println("try");
}
catch (Exception ex) {
System.out.println("catch");
}
finally {
System.out.println("finally");
}
try {
Integer.parseInt("test");
System.out.println("try");
}
catch (Exception ex) {
System.out.println("catch");
}
System.out.println("finally");
Answer the question
In order to leave comments, you need to log in
Finally guarantees the execution of the code, regardless of whether there was an error or not.
But what happens if the code that handles the exception throws the exception itself?
try
{
throw new ArgumentException();
}
catch(Exception)
{
// any new exception thrown here
}
CodeCleanup();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question