



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




























Object-Oriented Programming (OOP) Lecture No. 45
int function1(){ try{ FILE *fileptr = fopen(“filename.txt”,“w”); fwrite(“Hello World”,1,11,fileptr); ... throw exception(); fclose(fileptr); } catch(...) { fclose(fileptr); throw; } return 0; }
class FilePtr{ FILE * f; public: FilePtr(const char *name, const char * mode) { f = fopen(name, mode);} ~FilePtr() { fclose(f); } operator FILE * () { return f; } };
int function1(){
FilePtr file(“filename.txt”,“w”); fwrite(“Hello World”,1,11,file); throw exception(); ... return 0;
}
class Student{ String FirstName; String SecondName; String EmailAddress; … }
Student::Student (String aName) : name(aName)
/The constructor of String can throw a exception/
{
...
}
class Exception;
class Complex{
…
public:
~Complex(){ throw Exception(); }
};
Complex::~Complex()
{
try{ throw Exception(); } catch(…){ }
}