diff --git a/src/vstest.console/CommandLine/CommandLineOptions.cs b/src/vstest.console/CommandLine/CommandLineOptions.cs
index 64d212043b..4edd13929b 100644
--- a/src/vstest.console/CommandLine/CommandLineOptions.cs
+++ b/src/vstest.console/CommandLine/CommandLineOptions.cs
@@ -295,14 +295,10 @@ public void AddSource(string source)
// Get matching files from file pattern parser
matchingFiles = FilePatternParser.GetMatchingFiles(source);
}
- catch(TestSourceException ex)
+ catch(TestSourceException ex) when (source.StartsWith("-") || source.StartsWith("/"))
{
- if(source.StartsWith("-") || source.StartsWith("/"))
- {
- throw new TestSourceException(
- string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidArgument, source));
- }
- throw ex;
+ throw new TestSourceException(
+ string.Format(CultureInfo.CurrentUICulture, CommandLineResources.InvalidArgument, source), ex);
}
// Add the matching files to source list
this.sources = this.sources.Union(matchingFiles).ToList();
diff --git a/src/vstest.console/CommandLine/TestSourceException.cs b/src/vstest.console/CommandLine/TestSourceException.cs
index 0cb6903b17..05f5e734f2 100644
--- a/src/vstest.console/CommandLine/TestSourceException.cs
+++ b/src/vstest.console/CommandLine/TestSourceException.cs
@@ -25,7 +25,17 @@ public TestSourceException()
///
/// Message for the exception.
public TestSourceException(string message)
- : base(message)
+ : this(message, innerException: null)
+ {
+ }
+
+ ///
+ /// Initializes with the message and innerException.
+ ///
+ /// Message for the exception.
+ /// The exception that is the cause of the current exception, or a null reference.
+ public TestSourceException(string message, Exception innerException)
+ : base(message, innerException)
{
}