- #1
yungman
- 5,755
- 293
I followed the program from the book and it doesn't work. I simplified to show what's going on. I solve the problem and show in the second program. It's the good old cstring and the string literal again.
This is from the book, it doesn't work:
The error is:
I experimented and made it work, this is my program:
Only difference is I throw a cstring Cr that contain "Alan". It works.
This is my first day on this, I have no idea why the one in the book doesn't work and why it has to be like what I did to make it work.
Please help explain this.
Thanks
This is from the book, it doesn't work:
C++:
#include <iostream>
using namespace std;
int main() {
try
{
throw "Alan";//throw a string literal as in the book
}
catch (char *e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0;
}
The error is:
C++:
int main() {
try
{ char Cr[] = "Alan";
throw Cr;//Using cstring works.
}
catch (char* e)
{
cout << "An exception occurred. Exception Nr. " << e << '\n';
}
return 0;
}
Only difference is I throw a cstring Cr that contain "Alan". It works.
This is my first day on this, I have no idea why the one in the book doesn't work and why it has to be like what I did to make it work.
Please help explain this.
Thanks