Answer to Question #270401 in C++ for avinash

Question #270401

wap to show exception using try throw and catch block.


1
Expert's answer
2021-11-24T00:42:00-0500
#include <iostream>
using namespace std;
int main()
{
   int num = -1;
   cout << "Before try \n";
   try {
      cout << "try \n";
      if (num < 0)
      {
         throw num;
         cout << "After throw (Never executed) \n";
      }
   }
   catch (int num) {
      cout << "Exception Caught \n";
   }
 
   cout << "After exception catch  \n";
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS