Must "try" Have "catch" To Pair? in Programming Posted March 11, 2007 · Report reply Hi Programmers,To my knowledge, a try block can stand alone. But my compiler keepcomplaining untill I put a catch block after a try block. Below isthe code, what wrong did I do? Thanks.Brian #include <iostream>using namespace std;int f(int i){ try { cout << ++i << endl; } return 1;}int main(){ int n = 1; f(n); return 1;} Compiler Message:$ g++ test_try_catch.cpptest_try_catch.cpp: In function `int f(int)':test_try_catch.cpp:11: error: expected `catch' before numeric constanttest_try_catch.cpp:11: error: expected `(' before numeric constanttest_try_catch.cpp:11: error: expected identifier before numericconstanttest_try_catch.cpp:11: error: invalid catch parametertest_try_catch.cpp:11: error: expected `)' before numeric constanttest_try_catch.cpp:11: error: expected `{' before numeric constant
Must "try" Have "catch" To Pair?
in Programming
Posted · Report reply
Hi Programmers,
To my knowledge, a try block can stand alone. But my compiler keep
complaining untill I put a catch block after a try block. Below is
the code, what wrong did I do? Thanks.
Brian