Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b07acef

Browse files
committed
C#: Fix exception throwing
1 parent 6dfe90e commit b07acef

6 files changed

Lines changed: 9 additions & 9 deletions

File tree

csharp/extractor/Semmle.Extraction.CIL.Driver/InvalidAssemblyException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace Semmle.Extraction.CIL.Driver
44
{
5-
internal class InvalidAssemblyException : Exception
5+
public class InvalidAssemblyException : Exception
66
{ }
77
}

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static string GetOutputName(CSharpCompilation compilation,
171171
if (entry == null)
172172
{
173173
if (compilation.SyntaxTrees.Length == 0)
174-
throw new ArgumentNullException("No source files seen");
174+
throw new InvalidOperationException("No source files seen");
175175

176176
// Probably invalid, but have a go anyway.
177177
var entryPointFile = compilation.SyntaxTrees.First().FilePath;

csharp/extractor/Semmle.Extraction/Id.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public Label(int value) : this()
123123
public override string ToString()
124124
{
125125
if (!Valid)
126-
throw new NullReferenceException("Attempt to use an invalid label");
126+
throw new InvalidOperationException("Attempt to use an invalid label");
127127

128128
return "#" + Value;
129129
}
@@ -148,7 +148,7 @@ public override bool Equals(object? other)
148148
public void AppendTo(System.IO.TextWriter trapFile)
149149
{
150150
if (!Valid)
151-
throw new NullReferenceException("Attempt to use an invalid label");
151+
throw new InvalidOperationException("Attempt to use an invalid label");
152152

153153
trapFile.Write('#');
154154
trapFile.Write(Value);

csharp/extractor/Semmle.Extraction/TrapExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static TextWriter WriteColumn(this TextWriter trapFile, object o)
8686
case Enum _:
8787
return trapFile.WriteColumn((int)o);
8888
default:
89-
throw new ArgumentException(nameof(o));
89+
throw new NotSupportedException($"Unsupported object type '{o.GetType()}' received");
9090
}
9191
}
9292

csharp/extractor/Semmle.Extraction/TrapWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public TrapWriter(ILogger logger, PathTransformer.ITransformedPath outputfile, s
8181
compressionStream = fileStream;
8282
break;
8383
default:
84-
throw new ArgumentException(nameof(trapCompression));
84+
throw new ArgumentOutOfRangeException(nameof(trapCompression), trapCompression, "Unsupported compression type");
8585
}
8686

8787

@@ -264,7 +264,7 @@ private static string TrapExtension(CompressionMode compression)
264264
case CompressionMode.None: return "";
265265
case CompressionMode.Gzip: return ".gz";
266266
case CompressionMode.Brotli: return ".br";
267-
default: throw new ArgumentException(nameof(compression));
267+
default: throw new ArgumentOutOfRangeException(nameof(compression), compression, "Unsupported compression type");
268268
}
269269
}
270270

csharp/extractor/Semmle.Util/CanonicalPathCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public enum Symlinks
212212
public CanonicalPathCache(int maxCapacity, PathStrategy pathStrategy)
213213
{
214214
if (maxCapacity <= 0)
215-
throw new ArgumentOutOfRangeException("Invalid cache size specified");
215+
throw new ArgumentOutOfRangeException(nameof(maxCapacity), maxCapacity, "Invalid cache size specified");
216216

217217
this.maxCapacity = maxCapacity;
218218
this.pathStrategy = pathStrategy;
@@ -278,7 +278,7 @@ public static CanonicalPathCache Create(ILogger logger, int maxCapacity, Symlink
278278
pathStrategy = new QueryDirectoryStrategy();
279279
break;
280280
default:
281-
throw new ArgumentOutOfRangeException("Invalid symlinks option");
281+
throw new ArgumentOutOfRangeException(nameof(symlinks), symlinks, "Invalid symlinks option");
282282
}
283283

284284
return new CanonicalPathCache(maxCapacity, pathStrategy);

0 commit comments

Comments
 (0)