Prev: Clean Cannot run my application outside VS without previously doing a "clean" before rebuild
Next: Evetlog
From: nicol on 6 May 2010 04:20 Hi Error 1 Property or indexer 'System.Exception.Message' cannot be assigned to -- it is read only using System; namespace ConsoleApplication126 { class Program { static void Main(string[] args) { string x = null; try { if (x == null) { Exception ex = new Exception(); ex.Message = "x was null"; // ****** error** throw ex; } } catch (Exception ex) { Console.WriteLine(ex); } } } }
From: Alberto Poblacion on 6 May 2010 04:39 "nicol" <nicol.young20(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");
From: nicol on 6 May 2010 07:13 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 ? ? ?
From: Family Tree Mike on 6 May 2010 07:20 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. -- Mike
From: Harlan Messinger on 6 May 2010 09:26 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.
|
Next
|
Last
Pages: 1 2 Prev: Clean Cannot run my application outside VS without previously doing a "clean" before rebuild Next: Evetlog |