0
What is the meaning of catch block in c++. Explain in detail.
3 Answers
0
When you 'try' to put an item on a shelf and that shelf exists. Then your 'try' succeeded.
When you 'try' to put an item on a shelf and that shelf does not exist. Then your 'try' failed and you're attempting to 'catch' your error.
In a real programming example. When you try to open a file and that file does not exist. You need to handle what to do when the file isn't there.
0
'Catch' statement always catch the errors thrown by 'Try' block. It simply execute a code inside it for particular error.
Let say if you have division program and someone enters a value by which the denominator becomes zero at that time try bock will send error to catch block which then execute a code which may be something like "an error in input".
0
try {
int motherAge = 29;
int sonAge = 36;
if (sonAge > motherAge) {
throw 99;
}
}
catch (int x) {
cout<<"Wrong age values - Error "<<x;
}