partialfailure.cpp

来自「是内存受限系统设计的代码。」· C++ 代码 · 共 27 行

CPP
27
字号

#include <iostream.h>
#include <Memory>

using namespace std;

class NetworkInterfaceClass { public:
  void doSomethingWhichCallsAnException() { throw "hello"; }
  ~NetworkInterfaceClass() { cout << "dtor called"; }
};


int main() {
  auto_ptr<char> c;
  try {
    auto_ptr<NetworkInterfaceClass> p(new NetworkInterfaceClass);
    p->doSomethingWhichCallsAnException();  // p is now orphaned
    NetworkInterfaceClass* q = p.release();
  }
  catch ( ... ) {
    cout << "Exception caught\n";
  }
  return 0;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?