// Base Class
class Base
{
public:
void RegisterWithServer();
// some more functions
protected:
Base(std::string aTestName, std::string aServerName);
~Base();
private:
std::string mString;
std::string mServerName;
yami::agent mYAMIAgent;
};
// Base Class constructor
Base::Base(string aTargetName, string aServerName):
mString(aTargetName),
mServerName(aServerName)
{
// my debug statment
cout <<" we are in Base Class constructor"<< std::endl;
cout <<" in normal case we get this debug statement but in case of crash it doesnt reach till here I suppose "<< endl;
}
// DerivedClass
class derivedClient: public Base
{
public:
derivedClient(std::string aceptedString);
virtual ~derivedClient();
private:
std::string mServerAddress;
std::string mServerName;
};
// constructor
derivedClient::derivedClient(string aceptedString):
Base(aceptedString, "ServerTest"),
mServerAddress(aceptedString),
mServerName ("ServerTest")
{
cout <<" in normal case we get this debug statement but in case of crash it doesnt reach till here I suppose "<< endl;
RegisterWithServer(); // call base class function
};
// in some other function in different file
some function()
{
.....
.....
try
{
if( meet certain condition)
{
......
......
cout <<" the code reached till here" << std::endl;
derivedClient dClient("192.168.2.110");// problem ??
cout <<"in case of crash below lines are not printed nor any message is printed from both constructors "<< std::endl;
}
}
catch( const yami::yami_logic_error & aYamiException)
{
cout << "error: " << aYamiException.what() << endl;
}
}
Hi Guys,
I am fixing the bug in the existing software .
Problem -> after some times the software stops responding .
What I have done -> I have traced the problem and found that when software crashes it fails before the object creation from dervived class.
The derived class calls dervived constructor and base constructor. I have added debug statement and found nothing is printed on debug.
I want to know why the code is not even going into derived class and base class ? is it possible that private variables have not been initialsed properly ?
Please throw some comments on sample code.
Thanks and regards,
Sam
I’m would guess that the constructor for
yami::agentthrows an exception which is why all the couts are not being run. As Oli mentioned in the comments all member variables of a class will be constructed before the class constructor is entered soyami::agent::agent()will be run beforeBase::Base()is entered.Edit:
If you have something like:
then m_Agent will get constructed using its default constructor which is declared as
agent(const parameters & options = parameters());. As you mention, for some reason yami::agent::agent() throws an exception which could due to any number of reasons such as a network initialization error, invalid input parameters, etc….If you want to specify custom parameters to the yami::agent constructor you can do something like:
What parameters you need may be different than what I use and the cause of the issue may not be even related to incorrect parameters. It could well be a low level networking error from the OS or even hardware.