Questions tagged [exception-specification]

47 questions
35
votes
1 answer

Questions about Hinnant's stack allocator

I've been using Howard Hinnant's stack allocator and it works like a charm, but some details of the implementation are a little unclear to me. Why are global operators new and delete used? The allocate() and deallocate() member functions use…
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
21
votes
5 answers

c++1z dynamic exception specification error

I am trying to compile my project with new GCC version 7.2.1 and have a problem with dynamic exception specifications: error: ISO C++1z does not allow dynamic exception specifications MEMORY_ALLOC_OPERATORS(SQLException) The problem is that these…
Pustovalov Dmitry
  • 998
  • 1
  • 9
  • 25
17
votes
2 answers

How can std::runtime_error::runtime_error(const std::string&) meet std::exception's requirement of throw()?

std::exception requires that its constructor be throw(). Yet std::runtime_error accepts a std::string as its argument, which indicates that it's storing a std::string somewhere. Therefore, an assignment or copy construction has to be going on…
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
16
votes
3 answers

Exception Specification

I know that this feature will be deprecated in C++0x, but for me as a total novice it seems like a good idea to have it. Could anyone explain to me why isn't a good idea?
There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194
14
votes
1 answer

Is there any point in declaring a deleted function as noexcept?

Consider these two possible definitions for a class: Exhibit A: struct A { A() = delete; }; Exhibit A′: struct A { A() noexcept = delete; } Is there any point in declaring a deleted function as noexcept?
user2296177
  • 2,807
  • 1
  • 15
  • 26
14
votes
1 answer

How does an exception specification affect virtual destructor overriding?

The C++ Standard states the following about virtual functions that have exception specifications: If a virtual function has an exception-specification, all declarations, including the definition, of any function that overrides that virtual function…
James McNellis
  • 348,265
  • 75
  • 913
  • 977
12
votes
1 answer

Why std::map find() is not declared as noexcept?

C++14 standard defines the find() member functions of std::map as follows: iterator find(const key_type& x); const_iterator find(const key_type& x) const; Why are these functions not defined as noexcept? What could possibly go wrong inside, that…
PowerGamer
  • 2,106
  • 2
  • 17
  • 33
12
votes
3 answers

Transitioning to C++11 where destructors are implicitly declared with noexcept

In C++11, a destructor without any exception specification is implicitly declared with noexcept, which is a change from C++03. Therefore, a code which used to throw from destructors in C++03 would still compile fine in C++11, but will crash at…
dragonroot
  • 5,653
  • 3
  • 38
  • 63
10
votes
2 answers

Why are C++ exception specifications not checked at compile-time?

I just read that in the C++11 standard revision, exception specifications were deprecated. I previously thought specifying what your functions may throw is good practice, but apparently, not so. After reading Herb Stutter's well-cited article, I…
Taral
  • 327
  • 1
  • 15
10
votes
11 answers

Is there a generally accepted idiom for indicating C++ code can throw exceptions?

I have seen problems when using C++ code that, unexpectedly to the caller, throws an exception. It's not always possible or practical to read every line of a module that you are using to see if it throws exceptions and if so, what type of…
David Coufal
  • 6,021
  • 5
  • 28
  • 30
9
votes
1 answer

Exception specifications when deriving from std::exception in C++11

I have an exception class as follows: #include struct InvalidPathException : public std::exception { explicit InvalidPathException() {} const char* what() const; }; const char* InvalidPathException::what() const { return…
beldaz
  • 4,299
  • 3
  • 43
  • 63
9
votes
2 answers

What is the exception specification for a defaulted virtual destructor in C++11?

Suppose I have: class Foo { public: virtual ~Foo()=default; }; What is the exception-specification on the defaulted destructor? Is the defaulted destructor equivalent to: virtual ~Foo() {}; or virtual ~Foo() throw() {}; or virtual…
user1414050
  • 99
  • 1
  • 2
7
votes
2 answers

How to get rid of "C++ exception specification ignored" warning

I recently got a dll that has been implemented by others. I have to use it in my application. In the header file of their class they have the function declaration void func1() throw (CCustomException); Now when i compile it am getting the…
liaK
  • 11,422
  • 11
  • 48
  • 73
7
votes
2 answers

Exception specification when overriding a virtual function

Consider the following code: class A { public: virtual void f() throw ( int ) { } }; class B: public A { public: void f() throw ( int, double ) { } }; When compiled, it says that derived class B has a looser throw specifier compared to A.…
jasonline
  • 8,646
  • 19
  • 59
  • 80
5
votes
1 answer

Exception specification in ˋtypedefˋ completely forbidden or only at toplevel?

In C++14 Sec 15.4;2 it is stated, that ... An exception-specification shall not appear in a typedef declaration or alias-declaration. That means the following is forbidden: typedef void (*fn)(int) noexcept; But does the the wording shall not appear…
chi
  • 309
  • 1
  • 4
1
2 3 4