What is the point of the finally block?

后端 未结 16 1215
长情又很酷
长情又很酷 2020-12-30 20:19

Syntax aside, what is the difference between

try {
}
catch() {
}
finally {
    x = 3;
}

and

try {
}
catch() {
}

x = 3;
         


        
16条回答
  •  悲哀的现实
    2020-12-30 21:16

    In Java:

    Finally always gets called, regardless of if the exception was correctly caught in catch(), or in fact if you have a catch at all.

提交回复
热议问题