【发布时间】:2015-12-19 04:12:01
【问题描述】:
我正在尝试捕获指针异常。我的代码看起来像这样。我收到“未处理的异常”。我做错了什么? 任何帮助将不胜感激。
#include <iostream>
#include <exception>
using namespace std;
struct Node{
int data;
Node* next;
};
int list_length(struct Node* head){
try{
int i = 0;
while (head->next){
head = head->next;
i++;
}
return i + 1;
}
catch (exception& e){
cout << e.what() << endl;
}
};
int main(void){
struct Node *perr = nullptr;
list_length(perr);
return 0;
}
【问题讨论】: