0

How do we achieve exception handling in c++ with an example.Can anyone tell plzz ..

7th Apr 2020, 5:17 PM
Disha Dey
Disha Dey - avatar
7 odpowiedzi
+ 1
Ok thank you for the help
7th Apr 2020, 5:45 PM
Disha Dey
Disha Dey - avatar
+ 1
#include <iostream> using namespace std; int main() { int no = -1; try{ if (no < 0) throw no; cout << "Success no = " << no; } catch(int n){ cout << "Negative no = " << n << endl; } return 0; } /* suppose you want your code to handle only positive number i.e no > 0 , so using exception handled one of the way is by doing this */
7th Apr 2020, 8:11 PM
RKK
RKK - avatar
0
Why does try didn't come in this?
7th Apr 2020, 5:38 PM
Disha Dey
Disha Dey - avatar
0
did you swipe right to see the other content?
7th Apr 2020, 5:39 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
Yes i did but there is throwing exection and catching expection only
7th Apr 2020, 5:41 PM
Disha Dey
Disha Dey - avatar
0
there is a ( try ) code in the last page. the link above has three pages.
7th Apr 2020, 5:43 PM
Bahhaⵣ
Bahhaⵣ - avatar