Re: GObject error handling questions



On Tue, 2013-05-21 at 09:17 +0400, Nikita Churaev wrote:
2. Is it possible to attach additional information to GError (file where
the error came from, line and column)? If not, what is the standard way
to report these?
No, GError::message is designed to be displayed on screen, error
targeted to developers shall be displayed in the terminal (probably
using g_error, or assertions). The domain and code shall be used
whenever run-time handling of the error shall be made. 

I'm implementing a parser and want it to report line and column of parse
errors (not where the g_set_error was in the .c file) and already know
that GError is not extensible.

What is the standard way of reporting additional error information in
GObject?


OK, I did this:

Made a factory class for my class:

TextgenTemplate *
textgen_template_parser_parse 
   (TextgenTemplateParser *parser, ..., GError **error);

TextgenLocation *
textgen_template_parser_get_error_location 
   (TextgenTemplateParser *parser);

And also added get_error_location to TextgenTemplate itself:

void 
textgen_template_run 
   (TextgenTemplate *tpl, ..., GError **error);

TextgenLocation *
textgen_template_get_error_location
   (TextgenTemplate *tpl);

Is it an OK way to report error locations?



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