How do I create custom GErrors domain and code?

To set a GErrors, I need to pass a domain and a code:

g_set_error(error,
            G_FILE_ERROR,
            G_FILE_ERROR_NOENT,
            "error message");

I want to pass my own domain and code, such as:

g_set_error(error,
            MY_ERROR_DOMAIN,
            MY_ERROR_DOMAIN_CODE,
            "error message");

I’ve read the Error Reporting page and a blog post about GErrors. I’m still unclear on what do I need to do to achieve what I want. Do I need to extend GError type in this case, for example, create a GMyError type?

Here’s an example.

1 Like
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.