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
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
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(…){ }
}