From: nicol on
On May 6, 5:26 pm, Harlan Messinger
<hmessinger.removet...(a)comcast.net> wrote:
> Family Tree Mike wrote:
> > On 5/6/2010 7:13 AM, nicol wrote:
> >> On May 6, 12:39 pm, "Alberto Poblacion"<earthling-
> >> quitaestoparacontes...(a)poblacion.org>  wrote:
> >>> "nicol"<nicol.youn...(a)gmail.com>  wrote in message
>
> >>>news:4f314dd6-1296-40a9-97b0-2e39a3214605(a)o8g2000yqo.googlegroups.com....
>
> >>>> Error 1 Property or indexer 'System.Exception.Message' cannot be
> >>>> assigned to -- it is read only
> >>>>                     Exception ex = new Exception();
> >>>>                     ex.Message = "x was null"; // ****** error**
>
> >>>      You can pass the message in the constructor:
>
> >>>      Exception ex = new Exception("x was null");
>
> >> thanks it work . . .   but could not code it in another way  ? ? ?
>
> > No, some objects have readonly properties such as this.  Only the .Net
> > developers would know the decision behind doing this for Exception.Message.
>
> My guess is that it's to keep handlers in the middle of the call stack
> from tampering with exceptions and then rethrowing them.

thanks of all
From: nicol on
On May 6, 5:26 pm, Harlan Messinger
<hmessinger.removet...(a)comcast.net> wrote:
> Family Tree Mike wrote:
> > On 5/6/2010 7:13 AM, nicol wrote:
> >> On May 6, 12:39 pm, "Alberto Poblacion"<earthling-
> >> quitaestoparacontes...(a)poblacion.org>  wrote:
> >>> "nicol"<nicol.youn...(a)gmail.com>  wrote in message
>
> >>>news:4f314dd6-1296-40a9-97b0-2e39a3214605(a)o8g2000yqo.googlegroups.com....
>
> >>>> Error 1 Property or indexer 'System.Exception.Message' cannot be
> >>>> assigned to -- it is read only
> >>>>                     Exception ex = new Exception();
> >>>>                     ex.Message = "x was null"; // ****** error**
>
> >>>      You can pass the message in the constructor:
>
> >>>      Exception ex = new Exception("x was null");
>
> >> thanks it work . . .   but could not code it in another way  ? ? ?
>
> > No, some objects have readonly properties such as this.  Only the .Net
> > developers would know the decision behind doing this for Exception.Message.
>
> My guess is that it's to keep handlers in the middle of the call stack
> from tampering with exceptions and then rethrowing them.

thanks of all
From: Arne Vajhøj on
On 06-05-2010 04:20, nicol wrote:
> Error 1 Property or indexer 'System.Exception.Message' cannot be
> assigned to -- it is read only

The error message explains what the problem is in plain English.

Arne
From: Arne Vajhøj on
On 06-05-2010 09:26, Harlan Messinger wrote:
> Family Tree Mike wrote:
>> On 5/6/2010 7:13 AM, nicol wrote:
>>> On May 6, 12:39 pm, "Alberto Poblacion"<earthling-
>>> quitaestoparacontes...(a)poblacion.org> wrote:
>>>> "nicol"<nicol.youn...(a)gmail.com> wrote in message
>>>> news:4f314dd6-1296-40a9-97b0-2e39a3214605(a)o8g2000yqo.googlegroups.com...
>>>>> Error 1 Property or indexer 'System.Exception.Message' cannot be
>>>>> assigned to -- it is read only
>>>>> Exception ex = new Exception();
>>>>> ex.Message = "x was null"; // ****** error**
>>>>
>>>> You can pass the message in the constructor:
>>>>
>>>> Exception ex = new Exception("x was null");
>>>
>>> thanks it work . . . but could not code it in another way ? ? ?
>>
>> No, some objects have readonly properties such as this. Only the .Net
>> developers would know the decision behind doing this for
>> Exception.Message.
>
> My guess is that it's to keep handlers in the middle of the call stack
> from tampering with exceptions and then rethrowing them.

Immutable classes is in general a good thing.

Arne