Nhatz HK Nhatz HK - 1 year ago 109
C++ Question

How do exceptions work in C++?

ebool keep_trying= true;
do {
char fname[80]; // std::string is better
cout Image "Please enter the file name: ";
cin Image fname;
try {
A= read_matrix_file(fname);
keep_trying= false;
} catch (cannot_open_file& e) {
cout Image "Could not open the file. Try another one!\n";
} catch (...)
cout Image "Something is fishy here. Try another file!\n";
} while (keep_trying);

This code is from Discovering modern c++. I don't understand what "A" in the try-block stand for and "e"(cannot_open_file& e) in the next catch-block

Answer Source

That appears to be an incomplete code snippet. You can assume that 'A' is of whatever type that read_matrix_file() returns. And 'e' is a reference to a cannot_open_file type, which should be defined somewhere else in the code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download