This is a discussion on try-throw-catch within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by anon Code: void FileHandling::ReadFile(const string& filename) throw( int ) Again you are saying you would throw int's. ...
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.
All the buzzt!
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
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.
It compiles and runs for me (VC++ 7.1). Not sure why you think it doesn't work.