title: glib, how to handle GError stuffs?
body: <p>I have this function :</p>
  
  <pre><code>static
  void ReadFilesInDirectory(const std::string &amp;target)
  {
      GDir *dir;
      GError *error;
      const gchar *filename;
      gchar* pathPlusFilename;
  
      dir = g_dir_open(target.c_str(), 0, &amp;error);
      while ((filename = g_dir_read_name(dir)))
      {
          pathPlusFilename = g_build_filename(target.c_str(),filename,(gchar*)NULL);
          if( g_file_test(pathPlusFilename ,G_FILE_TEST_IS_REGULAR) )
          {
              std::cout &lt;&lt; "(file)      " &lt;&lt; pathPlusFilename &lt;&lt; std::endl;
          }
          else
          {
              if( g_file_test(pathPlusFilename ,G_FILE_TEST_IS_DIR) )
              {
                  std::cout &lt;&lt; "(directory) " &lt;&lt; pathPlusFilename &lt;&lt; std::endl;
                  chdir(filename);
                  ReadFilesInDirectory(pathPlusFilename);
              }
          }
      }
      if(error) g_error_free(error); // gives an error at running time
      g_free(pathPlusFilename);
      g_dir_close(dir);
  }
  </code></pre>
  
  <p>there is a GError variable, but I don't know how to print something from a GError, <a href="http://sourcecodebrowser.com/glib2.0/2.25.8/gerror_8h.html" rel="nofollow">http://sourcecodebrowser.com/glib2.0/2.25.8/gerror_8h.html</a> . Running just that code trough a simple call from main like,</p>
  
  <pre><code> ReadFilesInDirectory("/home/user/pictures")
  </code></pre>
  
  <p>lead to an error at running time.</p>