+ 1
By using try-catch-finally, how to ensure that there will be no another error in finally block?
And what will be happen if there is error in finally block?
4 odpowiedzi
+ 2
another try and catch... finally is usually used to close / dispose unneeded data, if you get exception in there you might want to close the program...
+ 2
all errors should be caught, finally blocks are not supposed to do error handling, a work around would be to use a generic catch(Exception) which will ensure that any exceptions that fall through your catch statements are caught, a good use of the finally block would be to release a resource such as a db connection
+ 2
All possible errors must be found out beforehand and the proper code for handling these errors should be written in the Catch block. A generic Exception for any other unforeseen errors must be the concluding code of the Catch block. Finally block is used to execute statements irrespective of the errors happening or not; so here resource release and garbage collection must be written. An error in the finally block is rare except if specifically written by the programmer. This amounts to Bad Coding and should be avoided at all costs.
+ 1
You can make another try and catch inside finally block