gerror.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* gerror.h - Error reporting system
  2. *
  3. * Copyright 2000 Red Hat, Inc.
  4. *
  5. * The Gnome Library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public License as
  7. * published by the Free Software Foundation; either version 2 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * The Gnome Library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the Gnome Library; see the file COPYING.LIB. If not,
  17. * see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __G_ERROR_H__
  20. #define __G_ERROR_H__
  21. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  22. #error "Only <glib.h> can be included directly."
  23. #endif
  24. #include <stdarg.h>
  25. #include <glib/gquark.h>
  26. G_BEGIN_DECLS
  27. /**
  28. * GError:
  29. * @domain: error domain, e.g. #G_FILE_ERROR
  30. * @code: error code, e.g. %G_FILE_ERROR_NOENT
  31. * @message: human-readable informative error message
  32. *
  33. * The <structname>GError</structname> structure contains
  34. * information about an error that has occurred.
  35. */
  36. typedef struct _GError GError;
  37. struct _GError
  38. {
  39. GQuark domain;
  40. gint code;
  41. gchar *message;
  42. };
  43. GLIB_AVAILABLE_IN_ALL
  44. GError* g_error_new (GQuark domain,
  45. gint code,
  46. const gchar *format,
  47. ...) G_GNUC_PRINTF (3, 4);
  48. GLIB_AVAILABLE_IN_ALL
  49. GError* g_error_new_literal (GQuark domain,
  50. gint code,
  51. const gchar *message);
  52. GLIB_AVAILABLE_IN_ALL
  53. GError* g_error_new_valist (GQuark domain,
  54. gint code,
  55. const gchar *format,
  56. va_list args) G_GNUC_PRINTF(3, 0);
  57. GLIB_AVAILABLE_IN_ALL
  58. void g_error_free (GError *error);
  59. GLIB_AVAILABLE_IN_ALL
  60. GError* g_error_copy (const GError *error);
  61. GLIB_AVAILABLE_IN_ALL
  62. gboolean g_error_matches (const GError *error,
  63. GQuark domain,
  64. gint code);
  65. /* if (err) *err = g_error_new(domain, code, format, ...), also has
  66. * some sanity checks.
  67. */
  68. GLIB_AVAILABLE_IN_ALL
  69. void g_set_error (GError **err,
  70. GQuark domain,
  71. gint code,
  72. const gchar *format,
  73. ...) G_GNUC_PRINTF (4, 5);
  74. GLIB_AVAILABLE_IN_ALL
  75. void g_set_error_literal (GError **err,
  76. GQuark domain,
  77. gint code,
  78. const gchar *message);
  79. /* if (dest) *dest = src; also has some sanity checks.
  80. */
  81. GLIB_AVAILABLE_IN_ALL
  82. void g_propagate_error (GError **dest,
  83. GError *src);
  84. /* if (err && *err) { g_error_free(*err); *err = NULL; } */
  85. GLIB_AVAILABLE_IN_ALL
  86. void g_clear_error (GError **err);
  87. /* if (err) prefix the formatted string to the ->message */
  88. GLIB_AVAILABLE_IN_ALL
  89. void g_prefix_error (GError **err,
  90. const gchar *format,
  91. ...) G_GNUC_PRINTF (2, 3);
  92. /* g_propagate_error then g_error_prefix on dest */
  93. GLIB_AVAILABLE_IN_ALL
  94. void g_propagate_prefixed_error (GError **dest,
  95. GError *src,
  96. const gchar *format,
  97. ...) G_GNUC_PRINTF (3, 4);
  98. G_END_DECLS
  99. #endif /* __G_ERROR_H__ */