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
CODE
#include <iostream>
using namespace std;
int f(int i)
{
try {
cout << ++i << endl;
}
return 1;
}
int main()
{
int n = 1;
f(n);
return 1;
}
using namespace std;
int f(int i)
{
try {
cout << ++i << endl;
}
return 1;
}
int main()
{
int n = 1;
f(n);
return 1;
}
QUOTE
Compiler Message:
$ g++ test_try_catch.cpp
test_try_catch.cpp: In function `int f(int)':
test_try_catch.cpp:11: error: expected `catch' before numeric constant
test_try_catch.cpp:11: error: expected `(' before numeric constant
test_try_catch.cpp:11: error: expected identifier before numeric
constant
test_try_catch.cpp:11: error: invalid catch parameter
test_try_catch.cpp:11: error: expected `)' before numeric constant
test_try_catch.cpp:11: error: expected `{' before numeric constant
$ g++ test_try_catch.cpp
test_try_catch.cpp: In function `int f(int)':
test_try_catch.cpp:11: error: expected `catch' before numeric constant
test_try_catch.cpp:11: error: expected `(' before numeric constant
test_try_catch.cpp:11: error: expected identifier before numeric
constant
test_try_catch.cpp:11: error: invalid catch parameter
test_try_catch.cpp:11: error: expected `)' before numeric constant
test_try_catch.cpp:11: error: expected `{' before numeric constant

