On Fri, Dec 10, 2010 at 6:31 AM, Koen Deforche <[email protected]> wrote:
> Hey Sohail,
>
> 2010/12/8 Sohail Somani <[email protected]>:
>> On 10-12-08 11:19 AM, Koen Deforche wrote:
>>> I've fixed WRegExp so that passing it an invalid regular expession
>>> makes isValid() return false but does not throw an exception.
>>>
>>
>> Is that how Wt works in general? C++ best practice would state that
>> constructed objects should not be invalid and that constructors should
>> throw.
>
> In Wt::Dbo we throw exceptions, in Wt itself there is not much that
> can go wrong (in this sense). If it is a misuse of the API we throw an
> exception. If it is a problem with input (like this case), we mimic
> the behaviour of Qt, which is usually to indicate the error using an
> isValid() method. This is probably somewhat misguided and I would
> agree it is more correct to throw an exception instead. Fortunately,
> there is not alot of situations in Wt where an object construction can
> leave the object in an invalid state.
>
> Entirely personally, I find that a try {} catch block often breaks the
> legibility of the code, and for plain methods I prefer a return type
> check over an exception.

Personally I would prefer if the constructor throws, reasons are that
I want my app to die horribly if something *I* programmed, like a
regex, is wrong.  However, if I feed it a regex from an external
source (from the web page for example), then I will try/catch around
it because I do not trust user input in any way, shape, or form.

I have been putting less and less catches over time around my own
code, I program for what it 'should' do, else I want it to die
horribly and throw up a stack trace so I can see what I did wrong, I
do not want errors to propagate.

Given that though, user input is still highly untrusted, even if you
only 'think' it is a simple regex string.

------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to