Answer to Question #272522 in C++ for vhgfgy5

Question #272522

WAP to show multiple throw statement execution by using suitable example.


1
Expert's answer
2021-12-04T01:27:56-0500
#include <iostream>
#include<conio.h>
using namespace std;

int main()
{
    int a[3] = {-1,2};
    for(int i=0; i<2; i++)
    {
        int exception = a[i];
        try 
        {
            if (exception > 0)
                // throwing numeric value as exception
                throw exception;
            else
                // throwing a character as exception
                throw 'exception';
        } 
        catch (int exception)  // to catch numeric exceptions
        {
            cout << "Integer exception\n";
        } 
        catch (char exception) // to catch character/string exceptions
        {
            cout << "Character exception\n";
        }
    }
}


The above code illustrates multiple catch blocks to handle different types of exceptions in different ways


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