Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习红宝石。我正在尝试使用mysqlgem 连接到 MySQL db。我关心的一个问题是连接关闭。
mysql
我应该如何确保在异常抛出等意外情况下关闭连接?
你的意思是,像这样的东西?
begin db = open_mysql_connection # do stuff ensure # this block is always executed, even if exception is raised db.close end