title: C++ : Exception occurred in script: basic_string::_S_construct NULL not valid
body: <p>I am returning a string or NULL from the database function to the main program, sometimes i get this error from the exception: </p>
  
  <pre><code>basic_string::_S_construct NULL not valid
  </code></pre>
  
  <p>i think its because of the return NULL value from the database function? any ideas???</p>
  
  <pre><code>string database(string&amp; ip, string&amp; agent){
    //this is just for explanation
    .....
    ....
  
    return NULL or return string
  
  }
  
  int main(){
     string ip,host,proto,method,agent,request,newdec;
     httplog.open("/var/log/redirect/httplog.log", ios::app);
  
     try{
        ip = getenv("IP");
        host = getenv("CLIENT[host]");
        proto = getenv("HTTP_PROTO");
        method = getenv("HTTP_METHOD");
        agent = getenv("CLIENT[user-agent]");
  
        if (std::string::npos != host.find(string("dmnfmsdn.com")))
           return 0;
  
        if (std::string::npos != host.find(string("sdsdsds.com")))
           return 0;
  
        if (method=="POST")
           return 0;
  
        newdec = database(ip,agent);
        if (newdec.empty())
           return 0;
        else {
           httplog &lt;&lt; "Redirecting to splash page for user IP: " &lt;&lt; ip &lt;&lt; endl;
           cout &lt;&lt; newdec;
           cout.flush();
        }
        httplog.close();
        return 0; 
     }
     catch (exception&amp; e){
        httplog &lt;&lt; "Exception occurred in script: " &lt;&lt; e.what() &lt;&lt; endl;
        return 0;
     }
     return 0;
  }
  </code></pre>