Questions tagged [noexcept]

A C++ keyword used for exception-specifications and to query whether an expression can throw exceptions

When used at the end of a function declaration noexcept(constant)opt indicates whether or not a function can throw exceptions, replacing the deprecated C++03 form of exception specification using throw(…). If the constant expression in parentheses evaluates to true (or if the parentheses are omitted) it indicates the function will not throw, otherwise it indicates it might throw.

When used as an operator noexcept( expr ) does not evaluate the expression but returns a boolean indicating whether the expression cannot throw exceptions.

Use this tag for questions about either use of the noexcept keyword.

For the history and rationale of noexcept see Using noexcept

331 questions
1
vote
2 answers

Throwing exception in destructor of derived class

I am compiling a C++ library, and I have an issue with destructors and noexcept. It is my understanding that, since C++11, the default value of noexcept(...) inside destructors has changed. In particular, now destructors default to noexcept (that is…
bartgol
  • 1,703
  • 2
  • 20
  • 30
1
vote
3 answers

Can declaring POD types throw an exception?

When I declare a condition_variable, it may throw std::system_error. But how about when I declare a POD type (e.g. int, double or float)? Like the code below: int main() { //do something int i; //will here throw exception? } If declaring…
Caesar
  • 971
  • 6
  • 13
1
vote
2 answers

How to evaluate the result of the noexcept() operator

For example, template void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a,*b))); Under what condition will the function can, or cannot, throw an exception?
Milo Lu
  • 3,176
  • 3
  • 35
  • 46
1
vote
1 answer

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…
Nick
  • 9,962
  • 4
  • 42
  • 80
1
vote
2 answers

Are the implicit move ctor/assignmet operations noexcept? What about implicit copy operations?

The question titles says it all. I need to know if the default copy/move assignment/ctors implemented implicitly by the compiler are declared noexcept.
a06e
  • 18,594
  • 33
  • 93
  • 169
1
vote
2 answers

C++ noexcept specification depending on data members

this declaration is ok: void memberFunction(T& functor, double value)noexcept(noexcept(functor(value))); for a template class MyClass{ public: void memberFunction(T& functor, double…
jimifiki
  • 5,377
  • 2
  • 34
  • 60
1
vote
1 answer

How to find out whether an assignment operator of T in a function template throws an exception?

Here is my function template: template void f(vector &a) noexcept(noexcept( /* ??? */ )) I want to specify this function will not throw an exception given that the assignment operator = of T has noexcept specification. Is there a…
lz96
  • 2,816
  • 2
  • 28
  • 46
1
vote
0 answers

VS2015-preview: noexcept expression evaluation fails

I came across this issue trying out code in VS2015 preview. It appears MSVC has an issue evaluating the noexcept expression and causes the error message below. I've worked around the problem by hoisting the noexcept expression into a wrapper…
1
vote
1 answer

Can Clang warn me when I might throw an exception from a `noexcept` destructor?

C++11 specifies destructors as noexcept by default. Is there a way I can get Clang to report cases where my noexcept destructors might throw an exception (and hence call std::terminate)?
fbrereto
  • 35,429
  • 19
  • 126
  • 178
1
vote
0 answers

Noexcept specifier: why no compile time checks?

I'm studying the noexcept specifier and I am wondering about the reason behind some of its design decision. In particular, the reason why it doesn't make the same compile time checks as, for example, the constexpr specifier. I will explain this…
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
1
vote
1 answer

How should I handle exceptions in a state machine?

I call a lot of outside functions from within my state machine - either explicitly like sendMessage(...) or implicitly like a!=b. So far I have tried to keep track of what can throw, but as the number grows so does the need for a better method.…
odinthenerd
  • 5,422
  • 1
  • 32
  • 61
1
vote
1 answer

Should std::chrono::steady_clock::now be noexcept?

I've noticed that std::chrono::steady_clock::now has the noexcept specifier in the documentation at cplusplus.com. However, I haven't found any provision for this in the latest C++11 draft (unfortunately I don't have a copy of the standard). Is it a…
vitaut
  • 49,672
  • 25
  • 199
  • 336
0
votes
0 answers

Why is this move assignement operator implicitly deleted for unique_ptr?

I have a type pod that I'd like to pass a handle around using a unique_ptr with custom deleter. Only it doesn't work because the move assignement operator is implicitly deleted. I don't understand exactly why? The deleter is a pod type which…
glades
  • 3,778
  • 1
  • 12
  • 34
0
votes
1 answer

C++ noexcept operator

// Base class for noexcept testing class MyNoExcept { public: void Func() noexcept {} void Func1() {} }; // Derived class for noexcept testing class MyNoExcept2 : public MyNoExcept { public: void Func2()…
0
votes
0 answers

Enforce try-catch block to capture the exception thrown by object in Constructor

I would like to ensure that, **whenever a class that throws an exception is constructed, there is a try-catch block to capture the exception right there **. In the example, I would like to get a warning from compiler when I create A object in the…
Pax
  • 134
  • 5