C++.Coding.Standards.1918.Rules.Guidelines [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

C++.Coding.Standards.1918.Rules.Guidelines [Electronic resources] - نسخه متنی

Herb Sutter, Andrei Alexandrescu

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Exceptions


If you have to override a base class virtual function that already has an exception specification (e.g., ahem,

std::exception::what ), and you don't have the ability to change the class to remove the exception specifications (or to convince the class's maintainer to remove them), you will have to write a compatible exception specification on your overriding function, and you should prefer to make it no less restrictive than the base version so as to minimize the frequency with which it might be violated:

class Base {

// … // in a class written by someone else
virtual f()

throw( X, Y, Z ) ;

// the author used an exception specification,
};

// and if you can't get him to remove it…
class MyDerived : public Base {

// … // …then in your own class your override
virtual f()

throw( X, Y, Z ) ;

// must have a compatible (and preferably
};

// the identical) exception specification

[BoostLRG]'s experience is that a throws-nothing exception specification (i.e.,

throw() ) on a non-inline function "may have some benefit with some compilers." Not a stunning endorsement from one of the most highly regarded and expertly designed C++ library projects in the world.


/ 521