Questions about organizing catch statements in a catch block - compiler specific language or language?

I am currently using Visual Studio Express C ++ 2008, and I have some questions about ordering catch blocks. Unfortunately, I could not find the answer on the Internet, so I ask these questions to experts.

I notice that if catch (...) does not fit at the end of the catch block, compilation will fail with error C2311. For example, the following compilation:

catch (MyException)
{
}
catch (...)
{
}

while the following:

catch (...)
{
}
catch (MyException)
{
}

and. May I ask if this is defined in the C ++ language standard, or if it is just a Microsoft compiler that is strict?

b. Does C # and Java have the same rules?

. catch catch . . , ​​, ?

+5
3

. , .

a) catch(...) , .

b) # Java .

c) ( ) , . ,

+5

++ Standard 15.3/5 " ":

try . , , , .

A ... - ... ; . , ... try.

+3

catch(...) . . .

, , , "" , - ( , ).

, catch ( )

catch (int) {
  // ...
}
catch (int) {
  // ...
}

- -. , .

+3

All Articles