]> O.S.I.I.S - jp/crow.git/commitdiff
InstantiatorException with file name
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 17 Feb 2018 02:17:42 +0000 (03:17 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 17 Feb 2018 02:17:42 +0000 (03:17 +0100)
Tests/Showcase.cs
src/Instantiator.cs

index 59629dac1a06c9be587183d380afe176ee89b1a0..b21eaafa9feee3ee227348f690b09a1efe271dc8 100644 (file)
@@ -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);
                        }
index c75c8b9f6064ebce98c08988068758aef18e1934..a97f19d251ecd18f2d6126429b9b46f99037c058 100644 (file)
@@ -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);
 
        /// <summary>
@@ -70,27 +77,33 @@ namespace Crow.IML
                /// <summary>
                /// Initializes a new instance of the Instantiator class.
                /// </summary>
-               public Instantiator (string path) : this (Interface.GetStreamFromPath(path)) {
-                       sourcePath = path;
+               public Instantiator (string path) : this (Interface.GetStreamFromPath(path), path) {
+                       
                }
                /// <summary>
                /// Initializes a new instance of the Instantiator class.
                /// </summary>
-               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
+                       }
                }
                /// <summary>
                /// Initializes a new instance of the Instantiator class with an already openned xml reader