[gtkmm] The correct way to use Glib::Error?



Greetings,

  I'm not sure of the method of using Glib::Error in Gtkmm2.  Should I
throw short exceptions, pass pointers something else?

  I'm starting a port and I really don't want to have to go through
the error code twice.

  Are there any examples that show they way it's ment to be used?
If not, how would I implement the following pseudo code "properly"?

			      Thanks for any info,
				  Dale

  bool
  error_function(gint p1, gint p2, GError **error)
  {
    GError *sub_error = NULL;

    g_return_val_if_fail(error == NULL || *error == NULL, false);

    if (p1 != p2) {
      g_set_error(error, SUPPORT_ERROR, SUPPORT_ERROR_BADVALUE,
		  "Yeech! %d != %d", p1, p2);
      return false;
    }

    sub_error_function(&sub_error);
    if (sub_error != NULL) {
      g_propagate_error(error, sub_error);

      return false;
    }

    return true;
  }

  int
  main(int argc, char *argv[]) 
  {
    GError *error = NULL;

    ...

    if (!error_function(1, 2, &error)) {
      g_printf("Oops: %s\n", error->message);
      exit(1);
    }

    ...
  }

Attachment: pgpWxVSrEWW2D.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]