Question 6 Given the code below: class ExceptionA {}; class ExceptionB: public ExceptionA {}; class ExceptionC: public ExceptionA {}; void f1(int x) throw (ExceptionA, ExceptionB) { if (x % 2 != 0) throw ExceptionA (); throw ExceptionB(); } void f2 (int x) throw (ExceptionC, ExceptionA) { if (x <= 0) throw ExceptionC(); throw ExceptionA (); } } else void f3(int x) throw (ExceptionB, ExceptionC) { if (x 10) throw ExceptionB(); throw ExceptionC(); } else void f(void try { } else (*funcPointer) (int), int value) { funcPointer (value); } catch (ExceptionB) { cout << "Caught ExceptionB" << endl; } catch (ExceptionA) { cout << "Caught ExceptionA" << endl; } catch (ExceptionC) { } cout << "Caught ExceptionC" << endl; Write the output using the following main function: int main() { £ (£3, -10); £ (£3, 10); f(f2, -10); £ (£2, 10); f(f1, 20); f(fl, 11); return 0;

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

f18

In c++

Question 6
Given the code below:
class ExceptionA {};
class ExceptionB : public ExceptionA {};
class ExceptionC : public ExceptionA {};
void f1(int x) throw (ExceptionA, ExceptionB) {
if (x % 2 != 0)
throw ExceptionA ();
throw ExceptionB();
}
void
}
void
}
}
else
f2(int x) throw (ExceptionC, ExceptionA) {
if (x <= 0)
throw ExceptionC();
throw ExceptionA ();
}
else
f3(int x) throw (ExceptionB, ExceptionC) {
if (x < 10)
throw ExceptionB();
throw ExceptionC ();
void f(void
try {
else
(*funcPointer) (int), int value) {
funcPointer (value);
} catch (ExceptionB) {
cout << "Caught ExceptionB" << endl;
} catch (ExceptionA) {
cout << "Caught ExceptionA" << endl;
} catch (ExceptionC) {
}
cout << "Caught ExceptionC" << endl;
Write the output using the following main function:
int main() {
f(f3, -10);
f(f3, 10);
f(f2, -10);
f(f2, 10);
f(f1, 20);
f(fl, 11);
return 0;
Transcribed Image Text:Question 6 Given the code below: class ExceptionA {}; class ExceptionB : public ExceptionA {}; class ExceptionC : public ExceptionA {}; void f1(int x) throw (ExceptionA, ExceptionB) { if (x % 2 != 0) throw ExceptionA (); throw ExceptionB(); } void } void } } else f2(int x) throw (ExceptionC, ExceptionA) { if (x <= 0) throw ExceptionC(); throw ExceptionA (); } else f3(int x) throw (ExceptionB, ExceptionC) { if (x < 10) throw ExceptionB(); throw ExceptionC (); void f(void try { else (*funcPointer) (int), int value) { funcPointer (value); } catch (ExceptionB) { cout << "Caught ExceptionB" << endl; } catch (ExceptionA) { cout << "Caught ExceptionA" << endl; } catch (ExceptionC) { } cout << "Caught ExceptionC" << endl; Write the output using the following main function: int main() { f(f3, -10); f(f3, 10); f(f2, -10); f(f2, 10); f(f1, 20); f(fl, 11); return 0;
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Custom Exception class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT