How to report user errors



Hi,

I'm trying to lay out a strategy for implementing a way to report errors to users of a library I'm working on. The scenario is pretty similar to a GtkContainer which has multiple children in it, so for easy explanation I'll use it as an example.

Let's say the container class had a method which would perform an operation on all of it's children, and that this operation could fail. If an error occures somewhere down in the hierarchy I wan't the caller to be notified, a message, and if it was a child who
caused the error, report it too.

So the container method can not just _only_ return an error code, or a gboolean,
because in some cases I would need access to a possibly offending child.

One way I was thinking of was to use signals. Each child would provide an "error" signal, which the container would connect to. If a child fails, it emits the signal, the container gets notified, and then it knows which child failed, and itself can emit its own "error" signal, where
it provides the child as an argument.

So the caller of the container method would itself have to connect to the container error signal,
in order to get access to the error message, and a possibly offending child.

That is the basic scenario, my problem is slightly more complicated, as I have a "container" class, with children, but the children themself have "subchildren" which could also fail during the operation, and they might also need to report themself to the caller of the container method.

Would this strategy be labeled as misuse of GSignals ? :)

If so, what are the options ?

If anyone can think of "the right way" to do this, I'd appreciate it.

//Jacob




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