C# Programming - Exception Handling - Discussion
Discussion Forum : Exception Handling - General Questions (Q.No. 5)
5.
Which of the following statements are correct about exception handling in C#.NET?
- If an exception occurs then the program terminates abruptly without getting any chance to recover from the exception.
- No matter whether an exception occurs or not, the statements in the finally clause (if present) will get executed.
- A program can contain multiple finally clauses.
- A finally clause is written outside the try block.
- finally clause is used to perform clean up operations like closing the network/database connections.
Discussion:
11 comments Page 1 of 2.
Guest said:
1 decade ago
In that Finally is not Class, it is block. It is optional also to include in try catch. But when use Try statement, at least one catch statement should present. Throw will also option, it is used only user want to throw user exception.
Santosh said:
1 decade ago
Catch and finally are option block but you have to provide at least one of them catch or finally if you use a try block.
means,
try{}
catch{}
or
try {}
finally
{}
or
try{}
catch{}
finally{}
Not this:
try{}...
means,
try{}
catch{}
or
try {}
finally
{}
or
try{}
catch{}
finally{}
Not this:
try{}...
Surafel Kassahun said:
4 years ago
C# does not allow multiple finally blocks! And also finally block may or may not run every time depending on the type of exception that occurred.
Chandu said:
1 decade ago
According to me 2,4 & 5 is the right answer because, we can only write the finally block outside the try block, so option 3 holds good.
Matthew said:
9 years ago
According to me, the question is wrong. A *program* CAN contain multiple finally clauses. It cannot be *single try block*.
Andrue Cope said:
1 decade ago
2, 3, 4 and 5 are all correct. Most likely as @Santosh wrote we are supposed to find the incorrect statement which is 1.
Ramprasad said:
10 years ago
2, 4, 5 is correct. It is not in the answers. A finally clause is written outside the try block.
Gowri said:
1 decade ago
Which class is optional in Exception handling?
a) Finally
b) Catch
c) Throw
d) Try
a) Finally
b) Catch
c) Throw
d) Try
Santosh said:
1 decade ago
And yes this question is wrong you have to find incorrect option not correct option.
Vlad said:
1 decade ago
Question 3 should be - try block can contain multiple finally clauses.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers