jeudi 24 septembre 2015

Proper implementation of functions with noexcept C++11

Are those functions correctly implementing noexcept / throw()

Fisrst function

void do_something(const std::string s) noexcept{
    // do something with no exception
}

do_something("Hello");

"Hello" literal will create new std::string object and it might throw an exception.

Is this exception will be thrown outside of the function or inside?

Second function:

size_t do_something(const char *s) noexcept{
    return strlen(s);
}

do_something(nullptr);

strlen will crash, because s is nullprt. However this crash is nothing to do with exceptions. Is the assumption correct?

Aucun commentaire:

Enregistrer un commentaire