[Gtk-sharp-list] More finetuned error/exception handling in gapi
Philip Van Hoof
spam at pvanhoof.be
Sun Feb 10 16:39:46 EST 2008
I noticed this one in MethodBody.cs:
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw new GLib.GException (error);");
}
It would be nicer if I could put an exception creator here, in stead of
having to use GException. For example one that creates me a specific
type of Exception depending on the GError's domain and error code.
Just like last question, the one about the asynchronous APIs, is
something in place already to do this kind of things?
I took a look at GLib.ExceptionManager.UnhandledException but this
infrastructure doesn't make it possible for me to turn my exceptions
into specific ones.
I was thinking about something like this:
<add-node path="/api"><symbol name="ExceptionFactory" creater="Tny.ExceptionFactory.Create" /></add-node>
public class ExceptionFactory {
static ExceptionFactory instance = null;
static ExceptionFactory Instance {
if (instance == null)
instance = new ExceptionFactory ();
return instance;
}
XmlElement elem = null;
public XmlElement Elem {
get { return elem; }
set { elem = value; }
}
public override string ToString () {
if (elem != null)
return elem.GetAttribute ("creater");
return "new GLib.GException";
}
}
public void HandleException (StreamWriter sw, string indent)
{
if (!ThrowsException)
return;
sw.WriteLine (indent + "\t\t\tif (error != IntPtr.Zero) throw {0} (error);",
ExceptionFactory.Instance.ToString(););
}
And at Parser.cs:74:
case "symbol":
if (elem.GetAttribute ("name") == "ExceptionFactory")
ExceptionFactory.Instance.Elem = elem;
else
gens.Add (ParseSymbol (elem));
break;
--
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
http://pvanhoof.be/blog
http://codeminded.be
More information about the Gtk-sharp-list
mailing list