0

how to create own exception and what is pure virtual function.

I got the question on create own exeption for the array having size less than 0 .

31st May 2018, 2:00 AM
Pratik Mohite
Pratik Mohite - avatar
1 Antwort
+ 2
You can use the error types available in stdexcept to create your own execption messages. Eg : int arr[5]; int index; cin>>index; if(index>5||index<0) throw out_of_range("Index is out of bounds!"); Now, you can catch your exception by putting the above code in a try block and declaring a catch block below it like this : catch(exception& e) { cerr<<e.what(); } Note that I did not use the size example as arrays use sizes in unsigned form and thus int arr[-1] will become int arr[4294967295]. For knowing about pure virtual functions, you can visit : www.cplusplus.com/doc/tutorial/polymorphism https://www.sololearn.com/learn/CPlusPlus/1912/
31st May 2018, 3:03 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar