throw list

Jun 24, 2013 at 11:32am
Hi programmers))

// A.h

class A
{
.....
public:
void remove(int)
throw(MyExcept);
.....
};

// A.cpp

void A::remove(int pos)
throw(MyExcept)
{
...
}

GNU compiler requires throw list
void A::remove(int pos)// error
{
...
}

but in visual studio it's not an error

who can explain why? which one is more logical?


Last edited on Jun 24, 2013 at 11:33am
Jun 24, 2013 at 11:39am
Visual Studio doesn't implement throw specifications: http://msdn.microsoft.com/en-us/library/wfa0edys(v=vs.110).aspx
So it doesn't give an error.
Jun 24, 2013 at 11:49am
thanks
Jun 24, 2013 at 11:57am
The use of dynamic-exception-specifications is deprecated. - IS

Instead:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct A
{
    void foo() noexcept ; // will never throw

    void bar() ; // may throw

    // will never throw if default constructor of B will never throw
    // may thow otherwise
    A() noexcept( std::is_nothrow_default_constructible<B>::value ) ;
    
    // ...

    B b ;
};
Topic archived. No new replies allowed.