myclass::myclass(const std::wstring& processName,const std::wstring& dllName) 
{
	if ( (isValidDll(fileName)) && (isValidProcess(processName)) )
	{
	this->dllName = dllName;                                     
	this->processName = processName;
	memoryAddress = NULL;

	}
	else
	{
		throw; // what kind of exception should i throw for invalid arguments?
	}
}

im quite new to c++ exceptions and im curious to what advice or how you people would handle this type of exception. Say the user enters invalid arguments when trying to instantiate an object of mine....if the arguments are invalid...how should i handle it or what should i throw?

as stated before just curious as to how people would handle/deal with this! -thx

You can throw any exception to like, if you have a specific purpose that doesn't fit in the standard exceptions, then make your own:

#include <exception>

class InvalidProcessException : public std::exception {
  private:
    std::wstring message;
  public:
    InvalidProcessException(const std::wstring& aProcessName,const std::wstring& aDllName) : message("Invalid Process Exception with process name '" + aProcessName + "' for dll name '" + aDllName + "'!") { };
    const char* what() const throw() {
      return message.c_str();
    };
};

myclass::myclass(const std::wstring& processName,const std::wstring& dllName) throw(InvalidProcessException) //it is always good to announce what exception you might throw from this function.
{
  if ( (isValidDll(fileName)) && (isValidProcess(processName)) )
  {
    this->dllName = dllName;                                     
    this->processName = processName;
    memoryAddress = NULL;

  }
  else
    throw InvalidProcessException(processName,dllName); //throw your specific exception.
  }
}
commented: thank you makes sense! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.