Skip to content

Instantly share code, notes, and snippets.

@billkindle
Last active July 13, 2019 15:07
Show Gist options
  • Save billkindle/f6569199faf125468f0f1639d58b44fa to your computer and use it in GitHub Desktop.
Save billkindle/f6569199faf125468f0f1639d58b44fa to your computer and use it in GitHub Desktop.
This PowerShell code will return all currently loaded .NET error types. Usefull for Try / Catch / Finally blocks.
# Courtesy of https://www.sconstantinou.com/powershell-try-catch-finally/
# A great PowerShell blogger, Stephanos Constantinou
([appdomain]::CurrentDomain.GetAssemblies() |
Where-Object {$_.Location -ne $null} |
foreach {$_.GetExportedTypes() |
Where-Object {$_.Fullname -match 'Exception'}}).FullName
@billkindle
Copy link
Author

Adding the output for reference:

System.AggregateException
System.Exception
System.SystemException
System.OutOfMemoryException
System.StackOverflowException
System.DataMisalignedException
System.ExecutionEngineException
System.MemberAccessException
System.AccessViolationException
System.ApplicationException
System.AppDomainUnloadedException
System.ArgumentException
System.ArgumentNullException
System.ArgumentOutOfRangeException
System.ArithmeticException
System.ArrayTypeMismatchException
System.BadImageFormatException
System.CannotUnloadAppDomainException
System.TypeUnloadedException
System.ContextMarshalException
System.DivideByZeroException
System.DuplicateWaitObjectException
System.EntryPointNotFoundException
System.DllNotFoundException
System.FieldAccessException
System.FormatException
System.IndexOutOfRangeException
System.InsufficientMemoryException
System.InsufficientExecutionStackException
System.InvalidCastException
System.InvalidOperationException
System.InvalidProgramException
System.InvalidTimeZoneException
System.MethodAccessException
System.MissingFieldException
System.MissingMemberException
System.MissingMethodException
System.MulticastNotSupportedException
System.NotFiniteNumberException
System.NotImplementedException
System.NotSupportedException
System.NullReferenceException
System.ObjectDisposedException
System.OperationCanceledException
System.OverflowException
System.PlatformNotSupportedException
System.RankException
System.TimeoutException
System.TimeZoneNotFoundException
System.TypeAccessException
System.TypeInitializationException
System.TypeLoadException
System.UnauthorizedAccessException
System.UnhandledExceptionEventArgs
System.UnhandledExceptionEventHandler
System.IO.DirectoryNotFoundException
System.IO.DriveNotFoundException
System.IO.EndOfStreamException
System.IO.FileLoadException
System.IO.FileNotFoundException
System.IO.IOException
System.IO.PathTooLongException
System.IO.IsolatedStorage.IsolatedStorageException
System.Security.XmlSyntaxException
System.Security.SecurityException
System.Security.HostProtectionException
System.Security.VerificationException
System.Security.AccessControl.PrivilegeNotHeldException
System.Security.Cryptography.CryptographicException
System.Security.Cryptography.CryptographicUnexpectedOperationException
System.Security.Principal.IdentityNotMappedException
System.Security.Policy.PolicyException
System.Resources.MissingManifestResourceException
System.Resources.MissingSatelliteAssemblyException
System.Globalization.CultureNotFoundException
System.Diagnostics.Tracing.EventSourceException
System.Collections.Generic.KeyNotFoundException
System.Threading.AbandonedMutexException
System.Threading.LockRecursionException
System.Threading.SemaphoreFullException
System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException
System.Threading.ThreadStartException
System.Threading.WaitHandleCannotBeOpenedException
System.Threading.Tasks.TaskCanceledException
System.Threading.Tasks.TaskSchedulerException
System.Threading.Tasks.UnobservedTaskExceptionEventArgs
System.Reflection.AmbiguousMatchException
System.Reflection.CustomAttributeFormatException
System.Reflection.InvalidFilterCriteriaException
System.Reflection.ExceptionHandlingClauseOptions
System.Reflection.ExceptionHandlingClause
System.Reflection.ReflectionTypeLoadException
System.Reflection.TargetException
System.Reflection.TargetInvocationException
System.Reflection.TargetParameterCountException
System.Reflection.Emit.ExceptionHandler
System.Runtime.Serialization.SerializationException
System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptionsAttribute
System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs
System.Runtime.ExceptionServices.ExceptionDispatchInfo
System.Runtime.Remoting.RemotingException
System.Runtime.Remoting.ServerException
System.Runtime.Remoting.RemotingTimeoutException
System.Runtime.CompilerServices.RuntimeWrappedException
System.Runtime.InteropServices.COMException
System.Runtime.InteropServices.ExternalException
System.Runtime.InteropServices._Exception
System.Runtime.InteropServices.InvalidOleVariantTypeException
System.Runtime.InteropServices.MarshalDirectiveException
System.Runtime.InteropServices.SEHException
System.Runtime.InteropServices.InvalidComObjectException
System.Runtime.InteropServices.SafeArrayRankMismatchException
System.Runtime.InteropServices.SafeArrayTypeMismatchException
System.Text.DecoderExceptionFallback
System.Text.DecoderExceptionFallbackBuffer
System.Text.DecoderFallbackException
System.Text.EncoderExceptionFallback
System.Text.EncoderExceptionFallbackBuffer
System.Text.EncoderFallbackException
System.UriFormatException
System.Configuration.ConfigurationException
System.Configuration.SettingsPropertyIsReadOnlyException
System.Configuration.SettingsPropertyNotFoundException
System.Configuration.SettingsPropertyWrongTypeException
System.Net.CookieException
System.Net.HttpListenerException
System.Net.ProtocolViolationException
System.Net.WebException
System.Net.WebExceptionStatus
System.Net.WebSockets.WebSocketException
System.Net.Mail.SmtpException
System.Net.Mail.SmtpFailedRecipientException
System.Net.Mail.SmtpFailedRecipientsException
System.Net.NetworkInformation.NetworkInformationException
System.Net.NetworkInformation.PingException
System.Net.Sockets.SocketException
System.Threading.BarrierPostPhaseException
System.Threading.ThreadExceptionEventArgs
System.Threading.ThreadExceptionEventHandler
System.IO.InvalidDataException
System.IO.InternalBufferOverflowException
System.Security.Authentication.AuthenticationException
System.Security.Authentication.InvalidCredentialException
System.ComponentModel.InvalidAsynchronousStateException
System.ComponentModel.InvalidEnumArgumentException
System.ComponentModel.LicenseException
System.ComponentModel.WarningException
System.ComponentModel.Win32Exception
System.ComponentModel.Design.CheckoutException
System.CodeDom.CodeThrowExceptionStatement
System.Text.RegularExpressions.RegexMatchTimeoutException
System.Management.Instrumentation.InstrumentationBaseException
System.Management.Instrumentation.InstrumentationException
System.Management.Instrumentation.InstanceNotFoundException
System.Diagnostics.Eventing.Reader.EventLogException
System.Diagnostics.Eventing.Reader.EventLogNotFoundException
System.Diagnostics.Eventing.Reader.EventLogReadingException
System.Diagnostics.Eventing.Reader.EventLogProviderDisabledException
System.Diagnostics.Eventing.Reader.EventLogInvalidDataException
Microsoft.PowerShell.Commands.HelpCategoryInvalidException
Microsoft.PowerShell.Commands.HelpNotFoundException
System.Management.Automation.RemoteException
System.Management.Automation.ExtendedTypeSystemException
System.Management.Automation.MethodException
System.Management.Automation.MethodInvocationException
System.Management.Automation.GetValueException
System.Management.Automation.PropertyNotFoundException
System.Management.Automation.GetValueInvocationException
System.Management.Automation.SetValueException
System.Management.Automation.SetValueInvocationException
System.Management.Automation.PSInvalidCastException
System.Management.Automation.SettingValueExceptionEventArgs
System.Management.Automation.GettingValueExceptionEventArgs
System.Management.Automation.InvalidPowerShellStateException
System.Management.Automation.InvalidJobStateException
System.Management.Automation.JobFailedException
System.Management.Automation.WildcardPatternException
System.Management.Automation.FlowControlException
System.Management.Automation.LoopFlowException
System.Management.Automation.BreakException
System.Management.Automation.ContinueException
System.Management.Automation.ExitException
System.Management.Automation.TerminateException
System.Management.Automation.ScriptBlockToPowerShellNotSupportedException
System.Management.Automation.PSSecurityException
System.Management.Automation.CommandNotFoundException
System.Management.Automation.ScriptRequiresException
System.Management.Automation.ApplicationFailedException
System.Management.Automation.CmdletInvocationException
System.Management.Automation.CmdletProviderInvocationException
System.Management.Automation.PipelineStoppedException
System.Management.Automation.PipelineClosedException
System.Management.Automation.ActionPreferenceStopException
System.Management.Automation.ParentContainsErrorRecordException
System.Management.Automation.RedirectedException
System.Management.Automation.ScriptCallDepthException
System.Management.Automation.PipelineDepthException
System.Management.Automation.HaltCommandException
System.Management.Automation.MetadataException
System.Management.Automation.ValidationMetadataException
System.Management.Automation.ArgumentTransformationMetadataException
System.Management.Automation.ParsingMetadataException
System.Management.Automation.PSArgumentException
System.Management.Automation.PSArgumentNullException
System.Management.Automation.PSArgumentOutOfRangeException
System.Management.Automation.PSInvalidOperationException
System.Management.Automation.PSNotImplementedException
System.Management.Automation.PSNotSupportedException
System.Management.Automation.PSObjectDisposedException
System.Management.Automation.ParameterBindingException
System.Management.Automation.ParseException
System.Management.Automation.IncompleteParseException
System.Management.Automation.RuntimeException
System.Management.Automation.ProviderInvocationException
System.Management.Automation.SessionStateException
System.Management.Automation.SessionStateOverflowException
System.Management.Automation.SessionStateUnauthorizedAccessException
System.Management.Automation.ProviderNotFoundException
System.Management.Automation.ProviderNameAmbiguousException
System.Management.Automation.DriveNotFoundException
System.Management.Automation.ItemNotFoundException
System.Management.Automation.Remoting.PSRemotingDataStructureException
System.Management.Automation.Remoting.PSRemotingTransportException
System.Management.Automation.Remoting.PSRemotingTransportRedirectException
System.Management.Automation.Remoting.PSDirectException
System.Management.Automation.Host.HostException
System.Management.Automation.Host.PromptingException
System.Management.Automation.Runspaces.TypeTableLoadException
System.Management.Automation.Runspaces.InvalidRunspaceStateException
System.Management.Automation.Runspaces.RunspaceOpenModuleLoadException
System.Management.Automation.Runspaces.InvalidPipelineStateException
System.Management.Automation.Runspaces.InvalidRunspacePoolStateException
System.Management.Automation.Runspaces.RunspaceConfigurationAttributeException
System.Management.Automation.Runspaces.RunspaceConfigurationTypeException
System.Management.Automation.Runspaces.PSConsoleLoadException
System.Management.Automation.Runspaces.PSSnapInException
System.Management.Automation.Runspaces.FormatTableLoadException
Microsoft.Management.Infrastructure.CimException
System.Management.ManagementException
System.DirectoryServices.DirectoryServicesCOMException
System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectNotFoundException
System.DirectoryServices.ActiveDirectory.ActiveDirectoryOperationException
System.DirectoryServices.ActiveDirectory.ActiveDirectoryServerDownException
System.DirectoryServices.ActiveDirectory.ActiveDirectoryObjectExistsException
System.DirectoryServices.ActiveDirectory.SyncFromAllServersOperationException
System.DirectoryServices.ActiveDirectory.ForestTrustCollisionException
System.Xml.XmlException
System.Xml.Schema.XmlSchemaException
System.Xml.Schema.XmlSchemaValidationException
System.Xml.Schema.XmlSchemaInferenceException
System.Xml.Xsl.XsltException
System.Xml.Xsl.XsltCompileException
System.Xml.XPath.XPathException
Microsoft.SqlServer.Server.InvalidUdtException
System.Data.StrongTypingException
System.Data.TypedDataSetGeneratorException
System.Data.DataException
System.Data.ConstraintException
System.Data.DeletedRowInaccessibleException
System.Data.DuplicateNameException
System.Data.InRowChangingEventException
System.Data.InvalidConstraintException
System.Data.MissingPrimaryKeyException
System.Data.NoNullAllowedException
System.Data.ReadOnlyException
System.Data.RowNotInTableException
System.Data.VersionNotFoundException
System.Data.DBConcurrencyException
System.Data.InvalidExpressionException
System.Data.EvaluateException
System.Data.SyntaxErrorException
System.Data.OperationAbortedException
System.Data.SqlTypes.SqlTypeException
System.Data.SqlTypes.SqlNullValueException
System.Data.SqlTypes.SqlTruncateException
System.Data.SqlTypes.SqlNotFilledException
System.Data.SqlTypes.SqlAlreadyFilledException
System.Data.SqlClient.SqlException
System.Data.OleDb.OleDbException
System.Data.Odbc.OdbcException
System.Data.Common.DbException
System.Configuration.ConfigurationErrorsException
System.Configuration.Provider.ProviderException
Microsoft.PowerShell.Commands.CertificateProviderItemNotFoundException
Microsoft.PowerShell.Commands.CertificateNotFoundException
Microsoft.PowerShell.Commands.CertificateStoreNotFoundException
Microsoft.PowerShell.Commands.CertificateStoreLocationNotFoundException
System.Transactions.TransactionException
System.Transactions.TransactionAbortedException
System.Transactions.TransactionInDoubtException
System.Transactions.TransactionManagerCommunicationException
System.Transactions.TransactionPromotionException
Microsoft.PowerShell.Cmdletization.Cim.CimJobException
Microsoft.PowerShell.Commands.ProcessCommandException
Microsoft.PowerShell.Commands.ServiceCommandException
Microsoft.PowerShell.Commands.RestartComputerTimeoutException
System.Configuration.Install.InstallException
Microsoft.PowerShell.Commands.WriteErrorException
Microsoft.PowerShell.Commands.StringManipulation.FlashExtractWrapper.TemplateParsing.TemplateParsingException
Microsoft.PowerShell.Commands.StringManipulation.FlashExtractWrapper.FlashExtract.ProgramNotFoundException
Microsoft.PowerShell.Commands.StringManipulation.FlashExtractWrapper.FlashExtract.ResultNotFoundException
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
Microsoft.CSharp.RuntimeBinder.RuntimeBinderInternalCompilerException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment