10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[C#]try-catch-finally句でreturn文を使ったときの挙動

Posted at

個人メモです。

JavaについてはQiitaでも同様の話は投稿されてるみたいですが
C#では(自分で調べたところ)、Qiitaにないようでしたので投稿。

結論

Javaと同様、finally句があると、try句もしくはcatch句にreturn文を入れても
finally句を処理した後にreturn処理が行われます。

参考

try-catch-finally句内のreturnについて - Qiita
c# - Will code in a Finally statement fire if I return a value in a Try block? - Stack Overflow
c# - What really happens in a try { return x; } finally { x = null; } statement? - Stack Overflow

10
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?