0

What is the meaning of catch block in c++. Explain in detail.

12th Jul 2017, 7:19 AM
Coder
Coder - avatar
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.
12th Jul 2017, 7:24 AM
Trevor Wessel
Trevor Wessel - avatar
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".
12th Jul 2017, 7:26 AM
Mihir Patel
0
try { int motherAge = 29; int sonAge = 36; if (sonAge > motherAge) { throw 99; } } catch (int x) { cout<<"Wrong age values - Error "<<x; }
12th Jul 2017, 7:27 AM
Mihir Patel