I am trying to catch pointer exception. My code looks like this. I am getting "Unhandled exception". What is it that I am doing wrong? Any help will be appreciated.
#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;
}