[vlc-devel] [Patches] Dash: mostly cosmetics

Tobias Güntner fatbull at web.de
Tue Dec 6 13:17:51 CET 2011


Am 01.12.2011 12:15, schrieb Hugo Beauzée-Luyssen:
> That's exactly what I'm trying to do. However I guess your point here
> is STL is "our" code, while Qt is not. However the point stays, to me.

I was referring to Dash only. Qt and STL are both out of scope. Whether 
Qt does or does not handle exceptions is IMHO irrelevant to our discussion.

> We should check for bad_allow, bad_cast if we use references,
> bad_typeid and ios_base::failure.
> Saying that I've never encountered a code catching these exceptions
> would be falacious, but true nevertheless.

I'm not saying those exceptions must be caught explicitly. IMHO a 
generic catch(std::exception&) at the point of entry is often 
sufficient, and I'm sure you have encountered *that* before. ;)

> I'm not saying we should get read of the STL exceptions, just most of
> those in Dash, that are useless most of the time.

Oh, I see. I assumed you wanted to remove all exceptions, including 
non-Dash exceptions.

> Let's take a code sample :
>
> Representation.cpp :
>
> SegmentInfo*        Representation::getSegmentInfo          () //...
> {
>      if(this->segmentInfo == NULL)
>          throw ElementNotPresentException();
>
>      return this->trickModeType;
> }
>
> BasicCMManager.cpp:
>
> try
>      {
>          SegmentInfo* info = rep->getSegmentInfo();
>          //....
>      }
>      catch(ElementNotPresentException&e)
>      {
>          /*TODO Debug */
>      }
>
> The error is handled twice. One so we can raise, and one to catch the error.
> It looks clearer to me just to return the pointer, regardless of it's
> value, and check it just once.

I agree exceptions seem to be overkill in this case. But before 
rewriting it, please consider:
* Is BasicCMManager::getSegments really the best place to handle this error?
* Is returning an empty/incomplete result vector really the best way to 
handle this error?
* Is segmentInfo really optional?
* Should the error be propagated further?

> Again, I'm not saying anything about STL's exceptions. They're not
> handled for now anyway.

IMHO this must definitely be fixed. Not catching bad_alloc (or a base 
class thereof) is like ignoring the return value of malloc, i.e, a bug.

Regards,
Tobias




More information about the vlc-devel mailing list