Why exceptions are expensive

 

Many a times, i get to read from lots of places as, “.. don’t use generic exceptions, as they are very expensive .. instead use specific exceptions like devidebyzero .. blah .. blah ..” According to the MSDN Article from this link, it clearly states to use specific exception, but doesn’t give you as why to use specific exception.

You can read my comment beneath the article. If you don’t see that, here it is.

When you use the catch and cast that as generic exception, it then compares with the following set of exceptions. Which is definitely an unwanted comparison or type conversion with the exact exception that is caught and caused by the code..

Microsoft.Build.BuildEngine..::.InternalLoggerException
Microsoft.Build.BuildEngine..::.InvalidProjectFileException
Microsoft.Build.BuildEngine..::.InvalidToolsetDefinitionException
Microsoft.Build.BuildEngine..::.RemoteErrorException
Microsoft.Build.Framework..::.LoggerException
Microsoft.JScript..::.CmdLineException
Microsoft.JScript..::.ParserException
Microsoft.ManagementConsole.Advanced..::.PrimarySnapInDataException
Microsoft.ManagementConsole.Internal..::.PrimarySnapInDataException
Microsoft.VisualBasic.ApplicationServices..::.CantStartSingleInstanceException
Microsoft.VisualBasic.ApplicationServices..::.NoStartupFormException
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassContainingClassNotOptional
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassCouldNotFindEvent
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassNextItemCannotBeCurrentWebItem
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassNextItemRespondNotFound
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassUserWebClassNameNotOptional
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassWebClassFileNameNotOptional
Microsoft.VisualBasic.Compatibility.VB6..::.WebClassWebItemNotValid
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemAssociatedWebClassNotOptional
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemClosingTagNotFound
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemCouldNotLoadEmbeddedResource
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemCouldNotLoadTemplateFile
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemNameNotOptional
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemNoTemplateSpecified
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemTooManyNestedTags
Microsoft.VisualBasic.Compatibility.VB6..::.WebItemUnexpectedErrorReadingTemplateFile
Microsoft.VisualBasic.CompilerServices..::.IncompleteInitialization
Microsoft.VisualBasic.CompilerServices..::.InternalErrorException
Microsoft.VisualBasic.FileIO..::.MalformedLineException
System.AddIn.Hosting..::.AddInSegmentDirectoryNotFoundException
System.AddIn.Hosting..::.InvalidPipelineStoreException
System..::.ApplicationException
System.ComponentModel.Design..::.ExceptionCollection
System.Configuration.Provider..::.ProviderException
System.Configuration..::.SettingsPropertyIsReadOnlyException
System.Configuration..::.SettingsPropertyNotFoundException
System.Configuration..::.SettingsPropertyWrongTypeException
System.Data.Linq..::.ChangeConflictException
System.Diagnostics.Eventing.Reader..::.EventLogException
System.DirectoryServices.ActiveDirectory..::.ActiveDirectoryObjectExistsException
System.DirectoryServices.ActiveDirectory..::.ActiveDirectoryObjectNotFoundException
System.DirectoryServices.ActiveDirectory..::.ActiveDirectoryOperationException
System.DirectoryServices.ActiveDirectory..::.ActiveDirectoryServerDownException
System.DirectoryServices.Protocols..::.DirectoryException
System.IdentityModel.Selectors..::.CardSpaceException
System.IdentityModel.Selectors..::.IdentityValidationException
System.IdentityModel.Selectors..::.PolicyValidationException
System.IdentityModel.Selectors..::.ServiceBusyException
System.IdentityModel.Selectors..::.ServiceNotStartedException
System.IdentityModel.Selectors..::.StsCommunicationException
System.IdentityModel.Selectors..::.UnsupportedPolicyOptionsException
System.IdentityModel.Selectors..::.UntrustedRecipientException
System.IdentityModel.Selectors..::.UserCancellationException
System..::.InvalidTimeZoneException
System.IO.IsolatedStorage..::.IsolatedStorageException
System.IO.Log..::.SequenceFullException
System.Management.Instrumentation..::.InstrumentationBaseException
System.Management.Instrumentation..::.WmiProviderInstallationException
System.Net.Mail..::.SmtpException
System.Net.PeerToPeer..::.PeerToPeerException
System.Runtime.CompilerServices..::.RuntimeWrappedException
System.Runtime.Remoting.MetadataServices..::.SUDSGeneratorException
System.Runtime.Remoting.MetadataServices..::.SUDSParserException
System.Runtime.Serialization..::.InvalidDataContractException
System.Security.RightsManagement..::.RightsManagementException
System.ServiceModel.Channels..::.InvalidChannelBindingException
System..::.SystemException
System.Threading..::.LockRecursionException
System..::.TimeZoneNotFoundException
System.Web.Query.Dynamic..::.ParseException
System.Web.Security..::.MembershipCreateUserException
System.Web.Security..::.MembershipPasswordException
System.Web.UI..::.ViewStateException
System.Web.UI.WebControls..::.LinqDataSourceValidationException
System.Windows.Automation..::.NoClickablePointException
System.Windows.Automation..::.ProxyAssemblyNotLoadedException
System.Windows.Controls..::.PrintDialogException
System.Windows.Forms..::.AxHost..::.InvalidActiveXStateException
System.Windows.Xps..::.XpsException
System.Windows.Xps..::.XpsWriterException
System.Workflow.Activities.Rules..::.RuleException
System.Workflow.ComponentModel.Compiler..::.WorkflowValidationFailedException
System.Workflow.ComponentModel.Serialization..::.WorkflowMarkupSerializationException
System.Workflow.ComponentModel..::.WorkflowTerminatedException
System.Workflow.Runtime..::.WorkflowOwnershipException

Comments

Nice informative stuff.
Kitchen Sinks said…
Thanks for the sharing..good ..keep it up

Popular posts from this blog

Network Intrusion Detection using Supervised ML technique

Common mistakes by Interviewer

Keep the system active, to avoid the auto lock