Technical Discussion :: C++
Home > Technical Interview Q&A > C++ > Discussion
116 / 187
Explain multiple catch statements?
Answer:
It is possible that a program segment has more than one condition to throw an exception. In such case we can associate more than one catch statement with a try. For eg:
Try
{
//try block;
}
catch (type 1 arg)
{
// catch block1;
}
catch (type 2 arg)
{
// catch block 2;
}
……………….
……………….
Catch (type n arg)
{
// catch block n;
}
Asked In ::
Mohan
23 Feb, 2019 5:07 AM
It is possible that a program segment has more than one condition to throw an exception. In such case we can associate more than one catch statement with a try. For eg:
Try
{
//try block;
}
catch (type 1 arg)
{
// catch block1;
}
catch (type 2 arg)
{
// catch block 2;
}
……………….
……………….
Catch (type n arg)
{
// catch block n;
}
Try
{
//try block;
}
catch (type 1 arg)
{
// catch block1;
}
catch (type 2 arg)
{
// catch block 2;
}
……………….
……………….
Catch (type n arg)
{
// catch block n;
}