![cb1ae1ef87a1461d7f102a3a00915cd9.png](https://i-blog.csdnimg.cn/blog_migrate/fb3345f2025c500efd2fc442ee8d8f20.jpeg)
Discussion: Never throw while holding a resource not owned by a handle
讨论:持有没有被句柄管理的资源时切勿抛出异常
Reason(原因)
That would be a leak.
这会引发资源泄露。
![3ffc3ad73fef15b2f335c2c310db0b6c.png](https://i-blog.csdnimg.cn/blog_migrate/91975385da4c1745955aa589bf56cd9e.jpeg)
Example(示例)
void f(int i){ FILE* f = fopen("a file", "r"); ifstream is { "another file" }; // ... if (i == 0) return; // ... fclose(f);}
If i == 0 the file handle for a file is leaked. On the other hand, the ifstream for another file wil