What exactly does a finally
block in exception handling perform?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
finally block is mainly used to perform close statement for example con.close that is to close connection from database....try block is always followed by either catch block or finally (or both also)...If you once entered in the try block then your finally block will be definately execute except system error,exception in finally block....Main key point of finally block is that it always be executed even the exception is handled or not..
I use it a lot for cleaning up open resources when there are multiple return statements in a block of code, making the code a lot cleaner as you don't need to clone the same 'close resource' code before every return statement. It's guaranteed that the code will call the finally section, even if you do a return within the try section. It also helps with code safety in this instance, since the programmer could easily leave it out by accident.