You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2019/09/06 09:01:15 UTC
[lucenenet] 05/21: Lucene.Net.Support.Threading.ThreadClass: Added
IsDebug property to change the Join methods in tests so they throw new
exceptions to preserve stack trace information.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit e6fa61269ca0d115345734a5ec2f3a3ba62cd458
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Tue Sep 3 02:37:08 2019 +0700
Lucene.Net.Support.Threading.ThreadClass: Added IsDebug property to change the Join methods in tests so they throw new exceptions to preserve stack trace information.
---
src/Lucene.Net/Support/Threading/ThreadClass.cs | 36 ++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/src/Lucene.Net/Support/Threading/ThreadClass.cs b/src/Lucene.Net/Support/Threading/ThreadClass.cs
index a84de7a..a62cc12 100644
--- a/src/Lucene.Net/Support/Threading/ThreadClass.cs
+++ b/src/Lucene.Net/Support/Threading/ThreadClass.cs
@@ -106,6 +106,7 @@ namespace Lucene.Net.Support.Threading
// sure that the unwrapped exception type is caught by Lucene.Net
// so it can handle the control flow accordingly.
_exception = ex;
+ _exception.Data["OriginalMessage"] = ex.ToString();
}
}
@@ -236,12 +237,29 @@ namespace Lucene.Net.Support.Threading
}
/// <summary>
+ /// If <c>true</c> when <see cref="Join()"/>, <see cref="Join(long)"/> or <see cref="Join(long, int)"/> is called,
+ /// any original exception and error message will be wrapped into a new <see cref="Exception"/> when thrown, so
+ /// debugging tools will show the correct stack trace information.
+ /// <para/>
+ /// NOTE: This changes the original exception type to <see cref="Exception"/>, so this setting should not be used if
+ /// control logic depends on the specific exception type being thrown. An alternative way to get the original
+ /// <see cref="Exception.ToString()"/> message is to use <c>exception.Data["OriginalMessage"].ToString()</c>.
+ /// </summary>
+ public bool IsDebug { get; set; }
+
+ /// <summary>
/// Blocks the calling thread until a thread terminates
/// </summary>
public void Join()
{
_threadField.Join();
- IOUtils.ReThrowUnchecked(_exception);
+ if (_exception != null)
+ {
+ if (IsDebug)
+ throw new Exception(_exception.Data["OriginalMessage"].ToString(), _exception);
+ else
+ throw _exception;
+ }
}
/// <summary>
@@ -251,7 +269,13 @@ namespace Lucene.Net.Support.Threading
public void Join(long milliSeconds)
{
_threadField.Join(Convert.ToInt32(milliSeconds));
- IOUtils.ReThrowUnchecked(_exception);
+ if (_exception != null)
+ {
+ if (IsDebug)
+ throw new Exception(_exception.Data["OriginalMessage"].ToString(), _exception);
+ else
+ throw _exception;
+ }
}
/// <summary>
@@ -264,7 +288,13 @@ namespace Lucene.Net.Support.Threading
int totalTime = Convert.ToInt32(milliSeconds + (nanoSeconds*0.000001));
_threadField.Join(totalTime);
- IOUtils.ReThrowUnchecked(_exception);
+ if (_exception != null)
+ {
+ if (IsDebug)
+ throw new Exception(_exception.Data["OriginalMessage"].ToString(), _exception);
+ else
+ throw _exception;
+ }
}
/// <summary>