Overview
Features
Download
Documentation
Community
Add-Ons & Services

Design of Poco::Exception class

A general discussion forum.

Design of Poco::Exception class

Postby ahtoh » 18 Mar 2013, 16:15

I have several quistions about Poco::Exception base class. Please, could anybody explain me:
1) What is a reason to use throw() in the some functions' signatures of Poco::Exception class? I noticed only virtual functions have that kind of signature.
2) Why are not all additional functions declared as virtual, such as message(), displayText(), nested(), and code()?
3) Why is any exception in the hierarchy of Poco exceptions not using virtual inheritance?

I ask about this, because I have found myself in a situation where I need to have three kind of exception classes, two of them have some additional personal data and third has data from the both foregoing.
Obviously, I have options to implement this, my first thing was to create base class for each of the two with virtual inheritance from Poco::Exception (question 3).
When I started implementing third class using multiple virtual inheritance from the two bases it has never worked, because of nonvirtual stuff (question 2).

My next idea was to create my own base exception class, for this reason I examined the interface of Poco::Exception class carefully and found that only this class has members with throw() in their signatures (question 1).
Whole library except exception classes does not have throw() in members signatures, so I think this has a reason and I am not fully understand exception mechanism espeically from crossplatform point of view.

Now, I consider about creating two base class for special data, and then using nonvirtual multiple inheritance from Poco::Exception and my base classes.

Thanks for you answers in advance.
ahtoh
 
Posts: 4
Joined: 10 Jun 2011, 13:28
Location: Russia

Re: Design of Poco::Exception class

Postby alex » 20 Mar 2013, 04:53

ahtoh wrote:1) What is a reason to use throw() in the some functions' signatures of Poco::Exception class? I noticed only virtual functions have that kind of signature.

Because they are std::exception overrides.

ahtoh wrote:2) Why are not all additional functions declared as virtual, such as message(), displayText(), nested(), and code()?

Because they return Poco::Exception members; what would be the purpose of making them virtual?

ahtoh wrote:3) Why is any exception in the hierarchy of Poco exceptions not using virtual inheritance?

Because there is no multiple inheritance in the Poco exception hierarchy.
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Design of Poco::Exception class

Postby ahtoh » 21 Mar 2013, 16:12

alex wrote:
ahtoh wrote:1) What is a reason to use throw() in the some functions' signatures of Poco::Exception class? I noticed only virtual functions have that kind of signature.

Because they are std::exception overrides.


It is not true, according to the http://www.cplusplus.com/reference/exce ... =exception, only what method and destructor have this signature.
However className and name methods have the same signature.

alex wrote:
ahtoh wrote:2) Why are not all additional functions declared as virtual, such as message(), displayText(), nested(), and code()?

Because they return Poco::Exception members; what would be the purpose of making them virtual?


Declaring displayText method as a virtual method has sence, because it allows users who wants to create own excpetions to override algorithm which compiles whole message.
Also it has sense because it allows to call these methods unambiguously in multiple inheritance scenarios.

alex wrote:
ahtoh wrote:3) Why is any exception in the hierarchy of Poco exceptions not using virtual inheritance?

Because there is no multiple inheritance in the Poco exception hierarchy.


It is an obvious explanation. Although I am not shure, but I think that if exception classes inherite base class virtually it does not affect on nothing, because handling exceptions significantly harder procces than one additional inderection to access members of base class. At the same time it allows to use these classes as base classes in case of multiple inheritance if somebody wants to do it.
ahtoh
 
Posts: 4
Joined: 10 Jun 2011, 13:28
Location: Russia

Re: Design of Poco::Exception class

Postby alex » 22 Mar 2013, 16:44

ahtoh wrote:only what method and destructor have this signature. However className and name methods have the same signature.

There may have been a reason for it in the past, I'm not sure. If you want it changed, run tests, submit a pull request and we'll look into it.

ahtoh wrote:Declaring displayText method as a virtual method has sence, because it allows users who wants to create own excpetions to override algorithm which compiles whole message.

there are Exception::message(const std::string&) and extendedMessage(const std::string&) protected functions.

ahtoh wrote:I think that if exception classes inherite base class virtually it does not affect on nothing, because handling exceptions significantly harder procces than one additional inderection to access members of base class. At the same time it allows to use these classes as base classes in case of multiple inheritance if somebody wants to do it.

propose a change, submit pull request and we'll consider it.
alex
 
Posts: 1086
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron