[Mono-dev] [PATCH] Int32.Parse

Zoltan Varga vargaz at gmail.com
Thu Oct 20 07:06:20 EDT 2005


                                                    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
>
>
>
>



More information about the Mono-devel-list mailing list