You're right , but not thoroughly. I use new only after those two first throws, and the error happens on the first throw, before using new...
Printable View
Did you try removing it? Like this:Code:void ReadFile(const string& filename);
I tried running the code and found the problem. The issue was the same as the crash I mentioned earlier when you create a FileHandling object but don't call ReadFile. When you exit from ReadFile early (before the dynamic array is created) you get the same problem, it causes a crash when the FileHandling object is destroyed.
The reason is that you don't initialize vec, so when the destructor tries to delete it then it tries to call delete on a garbage memory location. The best solution of course is to use the vector class. But if you aren't allowed to, then just initialize vec to 0 in the constructor and the delete will not cause any problems if it is never set to another value.
Also, if you must keep the dynamic array, you should disable copying so that you don't get crashes when your class is copied.
Another thing: you use delete, but new[]. You must match the array and non-array forms of new and delete correctly. If you allocate with new[], you must deallocate with delete[].
Another note about throw(type):
Visual Studio doesn't support throw(type), so rather you should use throw(...) if anything at all. Unless you don't want your code to compile with Visual Studio.
The code will compile fine, it will just generate warnings. If you want exception specifications for whatever reason, then you'll have no problems porting your code to Visual Studio.
throw(int) doesn't work.
throw(...) does, though.
Visual Studio doesn't support throw(type) specifications, for whatever reason...
It compiles and runs for me (VC++ 7.1). Not sure why you think it doesn't work.
OK, so that's weird because I'm sure it didn't work in 2005.
In 2008 I just get a warning that the compiler ignores it because it's not implemented.