Browse Source

Use more appropriate exception types where possible.

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
911fd83c39
  1. 8
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 3
      ICSharpCode.Decompiler/Metadata/Dom.cs

8
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -489,8 +489,12 @@ namespace ICSharpCode.Decompiler.CSharp @@ -489,8 +489,12 @@ namespace ICSharpCode.Decompiler.CSharp
};
syntaxTree = new SyntaxTree();
foreach (var type in types)
foreach (var type in types) {
if (type.IsNil)
throw new ArgumentException("types contains null element");
RequiredNamespaceCollector.CollectNamespaces(type, typeSystem, decompileRun.Namespaces);
}
DoDecompileTypes(types, decompileRun, decompilationContext, syntaxTree);
RunTransforms(syntaxTree, decompileRun, decompilationContext);
return syntaxTree;
@ -708,7 +712,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -708,7 +712,7 @@ namespace ICSharpCode.Decompiler.CSharp
addNewModifier = members.Any(m => SignatureComparer.Ordinal.Equals(m, (IMember)entity));
break;
default:
throw new NotSupportedException();
throw new ArgumentOutOfRangeException();
}
}

3
ICSharpCode.Decompiler/Metadata/Dom.cs

@ -87,7 +87,8 @@ namespace ICSharpCode.Decompiler.Metadata @@ -87,7 +87,8 @@ namespace ICSharpCode.Decompiler.Metadata
var headers = Module.Reader.PEHeaders;
var resources = headers.CorHeader.ResourcesDirectory;
int index = headers.GetContainingSectionIndex(resources.RelativeVirtualAddress);
if (index < 0) throw new NotSupportedException();
if (index < 0)
throw new BadImageFormatException("RVA could not be found in any section!");
var sectionHeader = headers.SectionHeaders[index];
var sectionData = Module.Reader.GetEntireImage();
int totalOffset = resources.RelativeVirtualAddress + sectionHeader.PointerToRawData - sectionHeader.VirtualAddress;

Loading…
Cancel
Save