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:
The compiler (MSVC 6.0) gives following error:
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." ) ) );
However, when I use the commented line, it works fine. What's wrong here... In both the cases there is a string object.
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 : ';'
Thanks in advance.