[Mono-dev] [PATCH] Int32.Parse

Carlos Alberto Cortez calberto.cortez at gmail.com
Fri Oct 21 04:28:02 EDT 2005


Hello,

Ok, then let's keep as you said. The attached patch applies what you
suggested, and also added a method to retrieve the so-often-used
FormatException (I think it was kind of insane to have the exception
being thrown from different places with exactly the same message).

Carlos.

El jue, 20-10-2005 a las 13:06 +0200, Zoltan Varga escribió:
>                                                     Hi,
> 
>   I think it would be a little bit easier to return the actual
> exception to be thrown from the
> TryParse methods as an out argument, instead of adding this
> abstraction layer which
> cannot return more helpful exceptions messages like "Number '123' is
> not valid". We should
> also retain the tryParse argument so these exception objects are not
> creared if it is true.
> 
> So for example:
> 
> internal bool Parse (String number, bool tryParse, out int result, out
> Exception ex)
> {
> ...
>    if (something_is_wrong) {
>           if (!tryParse)
>              ex = new ArgumentException ("....");
>              return false;
>    }
> 
>                           Zoltan
> 
> On 10/20/05, Carlos Alberto Cortez <calberto.cortez at gmail.com> wrote:
> > Hey,
> >
> > Currently the Int32.TryParse method calls the Int32.Parse method, and
> > catches the exceptions. That's not the best behaviour, since
> > Int32.TryParse is designed to avoid the performance problems associated
> > with exception handling.
> >
> > The attached patch proposes an approach to keep the result of the
> > parsing as an enum, and based on it the methods decide whether they
> > throw an exception or not.
> >
> > I wanted you to take a look at it, since we need to decide the best
> > solution for this before changing the TryParse/Parse methods in other
> > types.
> >
> > Carlos.
> >
> >
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> >
> >
> >
> >
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tryparse.diff
Type: text/x-patch
Size: 12279 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20051021/17e3cb0b/attachment.bin 


More information about the Mono-devel-list mailing list