Re: Exception vs Boolean

Tech-Archive recommends: Fix windows errors by optimizing your registry



Cor Ligthert [MVP] wrote:
In my idea is the well written text from Scott, completely clear.

This is interesting, given that his clarification suggests that your
interpretation was not what was actually meant...

In VB it is easy to tell.
Never use an exception in a Sub because than giving back a Boolean or an
enum is more describing and as Scott wrote less consuming processing time.

No, a boolean or enum is *not* more descriptive than an exception. An
exception can give as much information as you want it to - a boolean or
an enum is a single value. Furthermore, turning the sub into a function
with a status code then demands that every call to it should check the
status code (assuming they care about error handling).

Do you really want to have to check a status code every time you add an
entry to a list?

Performance is a separate issue - have you read my page on it? Do you
have any experience of real life situations where exceptions were only
thrown in ways which most people would deem "reasonable" but where
performance was an issue?

Decide in a function if you can give a class with an error code in it.
Although in this case is in my idea throwing an exception more describing.

Translating this to C# gives than the answer on the exact OP question, you
should never let a Void method throw an exception but use a method that
gives back a boolean (or enum).

Well, I'm very glad you weren't part of designing the framework
classes. You'll find very few status codes there, and plenty of
exceptions being thrown by void methods.

Jon

.



Relevant Pages

  • Unable to Write to Event Log w/ Enterprise Library 2.0 in Win App
    ... ExceptionPolicy.HandleException(ex, "Sample Exception Policy") ... keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, ... configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, ... context, String name, IConfigurationSource configurationSource, ...
    (microsoft.public.dotnet.general)
  • Re: urgent: beta 2.0 error
    ... Microsoft Online Support ... An unhandled exception has occurred. ... |> | Request URL: ... Boolean& ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: IIS 7 Catastrophic Failure :: COMException :: Microsoft.JScript
    ... Catastrophic Failure response on the first page request made. ... Catastrophic failure (Exception from HRESULT: ... System.RuntimeTypeHandle._GetTypeByName(String name, Boolean ...
    (microsoft.public.inetserver.iis)
  • Re: Sharepoint 2007 - Installation Error - Failed to register SP servi
    ... The issue stems from the installer going to a remote computer for SQL Server. ... Server I have the following exception: ... exception, Boolean breakConnection) ... RunBehavior runBehavior, String resetOptionsString) ...
    (microsoft.public.sharepoint.portalserver)
  • SerializationException from Orchestration
    ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage currMsg) ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ... serviceId, Guid& instanceId, BTXServiceStaticState staticState) ...
    (microsoft.public.biztalk.general)