• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
返回主页

Chuck Lu

  • 博客园
  • 首页
  • 新随笔
  • 联系
  • 订阅
  • 管理

Does Dispose still get called when exception is thrown inside of a using statement?

Does Dispose still get called when exception is thrown inside of a using statement?

 Yes, using wraps your code in a try/finally block where the finally portion will call Dispose() if it exists. It won't, however, call Close() directly as it only checks for the IDisposable interface being implemented and hence the Dispose() method.

See also:

  • Intercepting an exception inside IDisposable.Dispose
  • What is the proper way to ensure a SQL connection is closed when an exception is thrown?
  • C# "Using" Syntax
  • C# USING keyword - when and when not to use it?
  • 'using' statement vs 'try finally'
  • What is the C# Using block and why should I use it?
  • Disposable Using Pattern
  • Does End Using close an open SQL Connection

 

posted @ 2020-04-02 10:41  ChuckLu  阅读(129)  评论(0)    收藏  举报
刷新页面返回顶部

公告

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3