[mythtv] [mythtv-commits] Ticket #1788: H264 tools patch

Martin Ebourne lists at ebourne.me.uk
Wed May 10 22:35:01 UTC 2006


On Wed, 10 May 2006 21:35:03 +0000, MythTV wrote:
> Comment (by jean-michel.bouffard at crc.ca):
>  The throw()'s are only there to formally show that the code doesn't
>  throw any exceptions so it has nothing to do with the error checking of
>  any C/C++ libs. In fact, in the current code there are no used C/C++
>  libs. It is sometime a standard practice to include the throw statement
>  in every function even if they are empty but they can be removed if not
>  in the coding standards of MythTV.

Exception specifications are arguably a broken feature of C++ and are
generally best avoided.

The throw() guarantees to the caller that no exceptions will be passed up
to the caller from the called function. It is rare that this helps the
caller in any way. What it does mean is:

1. If the compiler cannot be certain that no exceptions will be thrown
(which it often can't) then it will have to wrap your function
implementation in an invisible try { } catch(...) block to enforce this.
Depending on the implementation this can have a noticeable performance
impact.

2. If the catch(...) actually catches any exceptions it has to call
unexpected() which typically aborts the program. Usually any information
on the exception that caused this to happen is lost, rendering it a right
pain to debug.

In short, all pain no gain. The best thing to do is document in a comment
that the method should not throw any exceptions and leave it at that.

Cheers,

Martin.



More information about the mythtv-dev mailing list