How does the try catch finally block work?

后端 未结 6 1438
耶瑟儿~
耶瑟儿~ 2021-02-06 20:35

In C#, how does a try catch finally block work?

So if there is an exception, I know that it will jump to the catch block and then jump to the finally block.

6条回答
  •  无人共我
    2021-02-06 21:16

    Yes, the finally block gets run whether there is an exception or not.

    Try
        [ tryStatements ]
        [ Exit Try ]
    [ Catch [ exception [ As type ] ] [ When expression ]
        [ catchStatements ]
        [ Exit Try ] ]
    [ Catch ... ]
    [ Finally
        [ finallyStatements ] ] --RUN ALWAYS
    End Try
    

    See: http://msdn.microsoft.com/en-us/library/fk6t46tz%28v=vs.80%29.aspx

提交回复
热议问题