有一種方法可以處理異常,然後在拋出異常的代碼中移動到下一行 ?C++ - 在不丟失調用堆棧的情況下處理異常
實施例:
try {
cout << "Test Begin! 1... 2... 3..." << endl;
throw "A text!";
throw 1;
throw 2;
throw 3;
cout << "Yeah! Successful!!" << endl;
} catch (char* text) {
cout << ch << endl;
???(); //Go back to the previous line
}
catch (int i) {
cout << "Thrown " << i << endl;
???(); //Go back to the previous line
}
的output'll是:
Test Begin! 1... 2... 3...
A text!
Thrown 1
Thrown 2
Thrown 3
Yeah! Successful!!
當然,添加更多的try/catch塊。 –