Instead of throwing exceptions of pre-defined types like int, float, char, etc., we can create classes and throw those class types as exceptions. Empty classes are particularly useful in exception handling. Following program demonstrates throwing class types as exceptions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include<iostream> using namespace std; class ZeroError {}; void sum() { int a, b; cout<<“Enter a and b values: “; cin>>a>>b; if(a==0 || b==0) throw ZeroError(); else cout<<“Sum is: “<<(a+b); } int main()
The post How to throw exception of the class type appeared first on Coding Security.
How to throw exception of the class type
read more
Tidak ada komentar:
Posting Komentar