Skip to content

Commit

Permalink
Provide better exceptions and messages in case of errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Jul 11, 2018
1 parent bc97127 commit 8954486
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/IL/ILReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ ILInstruction LdToken(EntityHandle token)
return new LdTypeToken(typeSystem.ResolveAsType(token));
if (token.Kind.IsMemberKind())
return new LdMemberToken(typeSystem.ResolveAsMember(token));
throw new NotImplementedException();
throw new BadImageFormatException("Invalid metadata token for ldtoken instruction.");
}
}
}
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal override void CheckInvariant(ILPhase phase)

void CloneVariables()
{
throw new NotImplementedException();
throw new NotSupportedException("ILFunction.CloneVariables is currently not supported!");
}

public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
Expand Down
2 changes: 2 additions & 0 deletions ICSharpCode.Decompiler/Metadata/PEFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public PEFile(string fileName, PEReader reader)
{
this.FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
this.Reader = reader ?? throw new ArgumentNullException(nameof(reader));
if (!reader.HasMetadata)
throw new ArgumentException("PE file does not contain any metadata!");
this.Metadata = reader.GetMetadataReader();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace Ricciolo.StylesExplorer.MarkupReflection
{
internal class BamlBinaryReader : BinaryReader
{
// Methods
public BamlBinaryReader(Stream stream)
: base(stream)
{
}

public virtual double ReadCompressedDouble()
{
switch (this.ReadByte()) {
byte b = this.ReadByte();
switch (b) {
case 1:
return 0;
case 2:
Expand All @@ -27,8 +27,9 @@ public virtual double ReadCompressedDouble()
return ReadInt32() * 1E-06;
case 5:
return this.ReadDouble();
default:
throw new BadImageFormatException($"Unexpected byte sequence in ReadCompressedDouble: 0x{b:x}");
}
throw new NotSupportedException();
}

public int ReadCompressedInt32()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void EnsureInit()
int s = reader.ReadInt32();
int t = reader.ReadInt32();
if (((r != 0x600000) || (s != 0x600000)) || (t != 0x600000))
throw new NotSupportedException();
throw new BadImageFormatException("Magic value mismatch!");

initialized = true;
}
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Analyzers/AnalyzeContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void Analyze(IEntity entity)
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ protected IEnumerable<AnalyzerTreeNode> FetchChildren(CancellationToken ct)
}
}

AnalyzerTreeNode EntityTreeNodeFactory(IEntity result)
AnalyzerTreeNode EntityTreeNodeFactory(IEntity entity)
{
switch (result) {
if (entity == null) {
throw new ArgumentNullException(nameof(entity));
}

switch (entity) {
case ITypeDefinition td:
return new AnalyzedTypeTreeNode(td) {
Language = this.Language
Expand All @@ -92,7 +96,7 @@ AnalyzerTreeNode EntityTreeNodeFactory(IEntity result)
Language = this.Language
};
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(entity), $"Entity {entity.GetType().FullName} is not supported.");
}
}

Expand Down
6 changes: 3 additions & 3 deletions ILSpy/Images/Images.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected override ImageSource GetBaseImage(TypeIcon icon)
baseImage = Images.StaticClass;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(icon), $"TypeIcon.{icon} is not supported!");
}

return baseImage;
Expand Down Expand Up @@ -238,7 +238,7 @@ protected override ImageSource GetBaseImage(MemberIcon icon)
baseImage = Images.Event;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(icon), $"MemberIcon.{icon} is not supported!");
}

return baseImage;
Expand Down Expand Up @@ -303,7 +303,7 @@ private static ImageSource GetOverlayImage(AccessOverlayIcon overlay)
overlayImage = Images.OverlayCompilerControlled;
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException(nameof(overlay), $"AccessOverlayIcon.{overlay} is not supported!");
}
return overlayImage;
}
Expand Down

0 comments on commit 8954486

Please sign in to comment.