From: Jean-Philippe Bruyère Date: Sat, 17 Feb 2018 02:17:42 +0000 (+0100) Subject: InstantiatorException with file name X-Git-Tag: v0.9.5-beta~172 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=81355c4df1b311dca6150c48a477ee367c78e0bf;p=jp%2Fcrow.git InstantiatorException with file name --- diff --git a/Tests/Showcase.cs b/Tests/Showcase.cs index 59629dac..b21eaafa 100644 --- a/Tests/Showcase.cs +++ b/Tests/Showcase.cs @@ -88,7 +88,7 @@ namespace Tests GraphicObject g = this.CurrentInterface.Load (fi.FullName); crowContainer.SetChild (g); g.DataSource = this; - } catch (Exception ex) { + } catch (InstantiatorException ex) { showError (ex); } } @@ -102,8 +102,8 @@ namespace Tests NotifyValueChanged ("source", source); } - void showError(Exception ex) { - NotifyValueChanged ("ErrorMessage", ex.Message + ex.InnerException); + void showError(InstantiatorException ex) { + NotifyValueChanged ("ErrorMessage", ex.Path + ": " + ex.InnerException.Message); NotifyValueChanged ("ShowError", true); } void hideError () { @@ -124,7 +124,7 @@ namespace Tests crowContainer.SetChild (g); g.DataSource = this; } - } catch (Exception ex) { + } catch (InstantiatorException ex) { System.Diagnostics.Debug.WriteLine (ex.ToString ()); showError (ex); } diff --git a/src/Instantiator.cs b/src/Instantiator.cs index c75c8b9f..a97f19d2 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -38,6 +38,13 @@ using Crow.IML; namespace Crow.IML { + public class InstantiatorException : Exception { + public string Path; + public InstantiatorException (string path, Exception innerException) + : base ("ITor exception in " + path, innerException){ + Path = path; + } + } public delegate object InstanciatorInvoker(Interface iface); /// @@ -70,27 +77,33 @@ namespace Crow.IML /// /// Initializes a new instance of the Instantiator class. /// - public Instantiator (string path) : this (Interface.GetStreamFromPath(path)) { - sourcePath = path; + public Instantiator (string path) : this (Interface.GetStreamFromPath(path), path) { + } /// /// Initializes a new instance of the Instantiator class. /// - public Instantiator (Stream stream) + public Instantiator (Stream stream, string srcPath = null) { -#if DEBUG_LOAD + sourcePath = srcPath; + #if DEBUG_LOAD Stopwatch loadingTime = new Stopwatch (); loadingTime.Start (); -#endif - using (XmlReader itr = XmlReader.Create (stream)) { - parseIML (itr); - } - stream.Dispose (); -#if DEBUG_LOAD - loadingTime.Stop (); - Debug.WriteLine ("IML Instantiator creation '{2}' : {0} ticks, {1} ms", + #endif + try { + using (XmlReader itr = XmlReader.Create (stream)) { + parseIML (itr); + } + stream.Dispose (); + } catch (Exception ex) { + throw new InstantiatorException(sourcePath, ex); + } finally { + #if DEBUG_LOAD + loadingTime.Stop (); + Debug.WriteLine ("IML Instantiator creation '{2}' : {0} ticks, {1} ms", loadingTime.ElapsedTicks, loadingTime.ElapsedMilliseconds, imlPath); -#endif + #endif + } } /// /// Initializes a new instance of the Instantiator class with an already openned xml reader