lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject lucenenet git commit: preserve exception type
Date Thu, 05 Feb 2015 21:51:09 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master 5e9250f84 -> 74deb0d41


preserve exception type


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/74deb0d4
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/74deb0d4
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/74deb0d4

Branch: refs/heads/master
Commit: 74deb0d4182ad1e993f60eb4458508cb94255df1
Parents: 5e9250f
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Thu Feb 5 14:15:57 2015 -0500
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Thu Feb 5 14:15:57 2015 -0500

----------------------------------------------------------------------
 .../Store/MockDirectoryWrapper.cs               | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/74deb0d4/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
index 3ea5e4f..d220833 100644
--- a/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
+++ b/src/Lucene.Net.TestFramework/Store/MockDirectoryWrapper.cs
@@ -536,9 +536,9 @@ namespace Lucene.Net.Store
             }
         }
 
-        // sets the cause of the incoming ioe to be the stack
-        // trace when the offending file name was opened
-        private Exception FillOpenTrace(Exception t, string name, bool input)
+        // if there are any exceptions in OpenFileHandles
+        // capture those as inner exceptions
+        private Exception WithAdditionalErrorInformation(Exception t, string name, bool input)
         {
             lock (this)
             {
@@ -546,12 +546,12 @@ namespace Lucene.Net.Store
                 {
                     if (input && ent.Key is MockIndexInputWrapper && ((MockIndexInputWrapper)ent.Key).Name.Equals(name))
                     {
-                        t = new Exception(ent.Value.Message, ent.Value);
+                        t = CreateException(t, ent.Value);
                         break;
                     }
                     else if (!input && ent.Key is MockIndexOutputWrapper &&
((MockIndexOutputWrapper)ent.Key).Name.Equals(name))
                     {
-                        t = new Exception(ent.Value.Message, ent.Value);
+                        t = CreateException(t, ent.Value);
                         break;
                     }
                 }
@@ -559,6 +559,11 @@ namespace Lucene.Net.Store
             }
         }
 
+        private Exception CreateException(Exception exception, Exception innerException)
+        {
+            return (Exception)Activator.CreateInstance(exception.GetType(), exception.Message,
innerException);
+        }
+
         private void MaybeYield()
         {
             if (RandomState.NextBoolean())
@@ -592,11 +597,11 @@ namespace Lucene.Net.Store
 
                         if (!assertNoDeleteOpenFile)
                         {
-                            throw FillOpenTrace(new IOException("MockDirectoryWrapper: file
\"" + name + "\" is still open: cannot delete"), name, true);
+                            throw WithAdditionalErrorInformation(new IOException("MockDirectoryWrapper:
file \"" + name + "\" is still open: cannot delete"), name, true);
                         }
                         else
                         {
-                            throw FillOpenTrace(new AssertionException("MockDirectoryWrapper:
file \"" + name + "\" is still open: cannot delete"), name, true);
+                            throw WithAdditionalErrorInformation(new AssertionException("MockDirectoryWrapper:
file \"" + name + "\" is still open: cannot delete"), name, true);
                         }
                     }
                     else
@@ -776,7 +781,7 @@ namespace Lucene.Net.Store
                 // output, except for segments.gen and segments_N
                 if (!AllowReadingFilesStillOpenForWrite_Renamed && OpenFilesForWrite.Contains(name)
&& !name.StartsWith("segments"))
                 {
-                    throw FillOpenTrace(new System.IO.IOException("MockDirectoryWrapper:
file \"" + name + "\" is still open for writing"), name, false);
+                    throw WithAdditionalErrorInformation(new IOException("MockDirectoryWrapper:
file \"" + name + "\" is still open for writing"), name, false);
                 }
 
                 IndexInput delegateInput = @in.OpenInput(name, LuceneTestCase.NewIOContext(RandomState,
context));
@@ -1304,7 +1309,7 @@ namespace Lucene.Net.Store
 
             if (OpenFilesForWrite.Contains(name) && !name.StartsWith("segments"))
             {
-                throw (System.IO.IOException)FillOpenTrace(new System.IO.IOException("MockDirectoryWrapper:
file \"" + name + "\" is still open for writing"), name, false);
+                throw WithAdditionalErrorInformation(new IOException("MockDirectoryWrapper:
file \"" + name + "\" is still open for writing"), name, false);
             }
 
             IndexInputSlicer delegateHandle = @in.CreateSlicer(name, context);


Mime
View raw message