Jump to content
xisto Community

sunnysky

Members
  • Content Count

    1
  • Joined

  • Last visited

Posts posted by sunnysky


  1. 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

    #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.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


×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.