Re: question on try/catch

From: modemer (modemer_at_yahoo.com)
Date: 03/05/05

  • Next message: deancoo: "Re: integer or long overflow..."
    Date: Fri, 4 Mar 2005 21:33:52 -0500
    
    

    "xuatla" <xuatla@gmail.com> ??????:d0b4rc$ho5$1@daisy.noc.ucla.edu...
    > Hi,
    >
    > I tried the following code about try/catch (from cplusplus.com)
    >
    > // exceptions
    > #include <ciostream>
    > using namespace std;
    >
    > int main () {
    > char myarray[10];
    > try
    > {
    > for (int n=0; n<=10; n++)
    > {
    > if (n>9) throw "Out of range";
    > myarray[n]='z';
    > }
    > }
    > catch (char * str)

    should be:
        catch (char const *str)

    > {
    > cout << "Exception: " << str << endl;
    > }
    > return 0;
    > }
    >
    > It's expected to give "Exception: Out of range".
    > but i complied in g++ 3.3.3. and run it, the output is "Aborted".
    >
    > Anyone help me to explain what's wrong here? or normal?
    >
    > Thanks a lot!
    >
    > xuatla


  • Next message: deancoo: "Re: integer or long overflow..."

    Relevant Pages

    • __declspec(noreturn)
      ... void throw_error(char const* str) ... std::string msg; ... The compiler complains that not all paths return something. ...
      (microsoft.public.vc.language)
    • Re: namespaces conflict?
      ... You don't modify the str argument so make it char const *. ... you're using the compiler in a non conforming mode ...
      (comp.lang.cpp)
    • a question about boost.python
      ... using namespace std; ... I don't know how to write Jamfile, so I write a Makefile, it works if i ... it also works if I don't use `str' ... Rational.cpp:10: warning: unused parameter `Rational r' ...
      (comp.lang.python)
    • Re: stream input
      ... int i = 0; ... A portable solution involves writing some word for each use, ... char const* m_str; ...
      (comp.lang.cpp)
    • Re: implicit declaration of function error
      ... > void func(string str) { ... the using namespace std; ...
      (alt.comp.lang.learn.c-cpp)