exception class hierarchy

2

2b|!2b==?

If I have the ff classes

class A : public std::exception
{
};

class B : public A
{
};

class C : public A
{
};

class D: public B
{

}


In what order do I need to 'catch' thrown exceptions ? (particular
emphasis on classes B and C which have the same hierarchy
 
D

Daniel T.

2b|!2b==? said:
If I have the ff classes

class A : public std::exception
{
};

class B : public A
{
};

class C : public A
{
};

class D: public B
{

}


In what order do I need to 'catch' thrown exceptions ? (particular
emphasis on classes B and C which have the same hierarchy

Both C and B need to be caught before A, it can be in either order
though.
 
E

Erik Wikström

If I have the ff classes

class A : public std::exception
{
};

class B : public A
{
};

class C : public A
{
};

class D: public B
{

}


In what order do I need to 'catch' thrown exceptions ? (particular
emphasis on classes B and C which have the same hierarchy

If you draw the classes in a tree-like graph then you need to catch by
the types of lower levels before those of the upper levels. Nodes on the
same level can be in any order.

std::exception
|
|
A
/ \
/ \
B C
|
|
D

So, first D, then B and C (in any order), then A, and lastly std::exception.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top