Thread: exceptions: reuse <stdexcept> classes???

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    39

    exceptions: reuse <stdexcept> classes???

    Is it a good idea to use classes defined in stdexcept (logic_error, runtime_error... etc). I think it should be.

    Basically, I need to throw an exception with a printable message indicating a reason. I was wondering if I should write my own class for it or use logic_error or runtime_error of <stdexcept>.

    When thrown exception needs to be customized then it'd be a good idea to write a custom exception class. What do you think?

    Also, I'm getting a compile-time error when compiling this code:
    Code:
    string raison_str( "connect() failed, returned: " );
    raison_str += ret_code;
    raison_str += "WSAGetLastError() returned: ";
    raison_str += rcode;
          
    throw ( logic_error( raison_str ) );
    //      throw ( logic_error( string( "connect() failed." ) ) );
    The compiler (MSVC 6.0) gives following error:
    Code:
    C:\Ruchikar\RnD\wbsrvc1\Session.cpp(62) : error C2061: syntax error : identifier 'raison_str'
    C:\Ruchikar\RnD\wbsrvc1\Session.cpp(62) : error C2066: cast to function type is illegal
    C:\Ruchikar\RnD\wbsrvc1\Session.cpp(62) : error C2059: syntax error : ';'
    However, when I use the commented line, it works fine. What's wrong here... In both the cases there is a string object.

    Thanks in advance.
    <Signature
    name="Ruchikar"
    quote="discussions are forgotten, only code remains"/>

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    which line is line 62?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    249
    Originally posted by ygfperson
    which line is line 62?
    I think it start at the second line... or the first line...
    but hmmmmmmmmmmmm.,....
    what can I say.. ?
    C++
    The best

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    39
    Line 62 is:

    Code:
    throw ( logic_error( raison_str ) );
    <Signature
    name="Ruchikar"
    quote="discussions are forgotten, only code remains"/>

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Re: exceptions: reuse <stdexcept> classes???

    Originally posted by Ruchikar

    Code:
    string raison_str( "connect() failed, returned: " );
    raison_str += ret_code;
    /*
    raison_str += "WSAGetLastError() returned: ";
    raison_str += rcode;
       */ // comment this all 
    throw ( logic_error( raison_str ) );
    //      throw ( logic_error( string( "connect() failed." ) ) );
    Have you try it like above.... ???

    I think the problem came from the first line not from the line 62 even if the error does show in 62
    C++
    The best

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    39

    Unhappy

    It still doesn't work. I commented all the three appends:
    Code:
    string raison_str( "connect() failed, returned: " );
    /*
    raison_str += ret_code;
    raison_str += "WSAGetLastError() returned: ";
    raison_str += rcode;
    */
    throw ( logic_error( raison_str ) );
    // throw ( logic_error( string( "connect() failed." ) ) );
    and the compilation still fails with same error.
    <Signature
    name="Ruchikar"
    quote="discussions are forgotten, only code remains"/>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  3. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  4. Prime Number Generator... Help !?!!
    By Halo in forum C++ Programming
    Replies: 9
    Last Post: 10-20-2003, 07:26 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM