Should throw exception when validating data?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



i'm wondering if it is preferred practice to throw exception in this
circumstance. I have seen it done like that, but i have also read that you
should try to never throw an exception in circumstances where you can do
some test before the operation that would throw the test so that you can by
pass the exception handling which is an expensive operation.

So lets say the scenario is i have an object that is validating itself in
the business layer. When a property doesn't pass validation, i want the UI
to be able to display the failure reason, so the error message that the
business layer sets has to propogate to the UI.

I have seen it done where the object throws exception with special message
which is then caught in UI and displayed to user that way.

Another way i've seen it is the business object simply sets the operation to
return false meaning the validation failed, and it sets a member variable
with the error message so that it can then be accessed in the UI to display
the error message that way.

Any comments on the best practice for doing this?

thanks a bunch


.



Relevant Pages

  • Re: Cannot display throw new exception error message
    ... you can't see your error message, because your code doesn't reach the ... line where you throw your Exception. ... To display your custom message, your openFilemethod should look like: ... If you would have had a look at the FileReader API documentation, ...
    (comp.lang.java.programmer)
  • RE: Biztalk 2006 Tutorial 3
    ... There are some known issues w/ the tutorials. ... Below is the error message that appears in the event ... Exception type: ServiceCreationException ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
    (microsoft.public.biztalk.general)
  • RE: Concerns about exception string revealing internals/data about
    ... exceptions could return certain information as part of the error message. ... exception occurs in my program, is it possible that the exception error ... built in ADO objects in Visual Studio for Microsoft SQL Server. ... the build-in controls in SQL Server2000 or .Net winform/Asp.net controls? ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Concerns about exception string revealing internals/data about
    ... Sorry in last post I meant an "unhandled" exception should never be shown to ... exceptions could return certain information as part of the error message. ... built in ADO objects in Visual Studio for Microsoft SQL Server. ... the build-in controls in SQL Server2000 or .Net winform/Asp.net controls? ...
    (microsoft.public.dotnet.framework.clr)
  • RE: Biztalk 2006 Tutorial 3
    ... Below is the error message that appears in the event ... Exception type: ServiceCreationException ... Microsoft.BizTalk.XLANGs.BTXEngine.BTXSession._createOrRehydrateRealService(Guid& instanceId, IBTMessage currMsg) ... md, Objectargs, Object server, Int32 methodPtr, Boolean fExecuteInContext, ...
    (microsoft.public.biztalk.general)