gerror.h 3.9 KB

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