



























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Templates and Inheritance, In case of exception, First Attempt, Code duplication, Second Attempt, Exception in Constructors, Exception in Initialization List, Exceptions in Destructors are the points you can learn in this object oriented programming subject.
Typology: Slides
1 / 35
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(…){ }
}