no, my case is: An exception specification with an empty throw, as in void MyFunction(int i) throw(){ } tells the compiler that the function does not throw any exceptions.
【在 P********e 的大作中提到】 : ft : no error : in try block, who ever first, who throw first and then just to catch block
P*e
4 楼
大牛都去吃饭了 Here it is: void translate() throw(unknown_word,bad_grammar) { /* ... */ } explicitly states that it will only throw exception objects whose types are unknown_word or bad_grammar, or any type derived from unknown_word or bad_ grammar void foo() throw(){} which means foo() cannot throw any exception
【在 t*********2 的大作中提到】 : no, my case is: : An exception specification with an empty throw, as in : void MyFunction(int i) throw(){ : } : tells the compiler that the function does not throw any exceptions.
【在 P********e 的大作中提到】 : 大牛都去吃饭了 : Here it is: : void translate() throw(unknown_word,bad_grammar) { /* ... */ } : explicitly states that it will only throw exception objects whose types are : unknown_word or bad_grammar, or any type derived from unknown_word or bad_ : grammar : void foo() throw(){} : which means foo() cannot throw any exception
【在 P********e 的大作中提到】 : 大牛都去吃饭了 : Here it is: : void translate() throw(unknown_word,bad_grammar) { /* ... */ } : explicitly states that it will only throw exception objects whose types are : unknown_word or bad_grammar, or any type derived from unknown_word or bad_ : grammar : void foo() throw(){} : which means foo() cannot throw any exception
Following declaration gives a message to the user of your class: my method doesn't throw any exception. Don't bother to put a try/catch block around it when you use it. void A::foo() throw(); It's your responsibility not to throw an exception in the definition of your method. Say void A::foo() throw() { throw (5); // you are doomed here. } The compiler won't give an error on above code. But you will get a run time error (your program aborts) if you implemented it this way.