我有一些看起来像这样的 C++ 代码:
void Student::addCourse(Course cVal, string gr) throw(...) {
try {
GradedCourse c(cVal, gr); // If an exception is thrown here...
coursesTaken.insert(c); // will this statement be executed?
} catch(...) {
throw;
}
}
如果构造函数发现包含课程成绩的 是无效的,构造GradedCourse
函数可能会抛出异常。gr
如果发生这种异常,是否会try
执行块内的任何进一步语句?我可以确定这样的异常不会导致不尝试插入GradedCourse
(coursesTaken
这是一个 STL 集)吗?我搜索了 Stack Overflow 和 Google,但都没有成功。