Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
AnswerRe: Editable Grid Pin
albCode3-Jan-06 0:15
albCode3-Jan-06 0:15 
GeneralRe: Editable Grid Pin
ProffK3-Jan-06 0:30
ProffK3-Jan-06 0:30 
GeneralRe: Editable Grid Pin
joe carbone3-Jan-06 3:56
joe carbone3-Jan-06 3:56 
QuestionDisabling compiler error? Pin
joachimj2-Jan-06 23:31
joachimj2-Jan-06 23:31 
AnswerRe: Disabling compiler error? Pin
mav.northwind3-Jan-06 0:19
mav.northwind3-Jan-06 0:19 
GeneralRe: Disabling compiler error? Pin
joachimj3-Jan-06 1:38
joachimj3-Jan-06 1:38 
AnswerRe: Disabling compiler error? Pin
Colin Angus Mackay3-Jan-06 2:12
Colin Angus Mackay3-Jan-06 2:12 
GeneralRe: Disabling compiler error? Pin
joachimj3-Jan-06 2:58
joachimj3-Jan-06 2:58 
Colin Angus Mackay wrote:
> The compiler is intelligent enough to realise this. There must be some other particular path through
> the method that is not returning a value or throwing an exception.

Are you sure? Perhaps there is an error in my code then.. Here it is;

public interface SomeInterface
{
   void ChangeState();
   int SomeFunction(int arg);
   int SomeMethodWithSideEffect();
   int SomeProperty
   {
      get;
      set;
   }
} // interface SomeInterface

class MessyNullObjectVersion : SomeInterface
{
   public void ChangeState() { throw new ApplicationException("Cannot set properties or change state of null objects."); }
   public int SomeFunction(int arg) { return arg; }
   public int SomeMethodWithSideEffect() { throw new ApplicationException("Cannot set properties or change state of null objects."); }
   public int SomeProperty
   {
      get { return 0; }
      set { throw new ApplicationException("Cannot set properties or change state of null objects."); }
   }
} // class MessyNullObjectVersion

class MaintainableNullObjectVersion : SomeInterface
{
   public void ChangeState() { NullObjectHelper.Throw_InvalidToCallOrSetOnNullObject(); }
   public int SomeFunction(int arg) { return arg; }
   public int SomeMethodWithSideEffect() { NullObjectHelper.Throw_InvalidToCallOrSetOnNullObject(); }
   public int SomeProperty
   {
      get { return 0; }
      set { NullObjectHelper.Throw_InvalidToCallOrSetOnNullObject(); }
   }
} // class MaintainableNullObjectVersion

class NullObjectHelper
{
   public static void Throw_InvalidToCallOrSetOnNullObject()
   {
      throw new ApplicationException("Cannot set properties or change state of null objects.");
   }
} // class NullObjectHelper

The 'Messy' version will compile just fine, but the 'Maintainable' version will say something on the lines of 'SomeMethodWithSideEffect - not all code paths return a value'.

I have a hard time seeing how 'SomeMethodWithSideEffect' can avoid throwing an exception... Please explain.

--
Ubi Signo?
GeneralRe: Disabling compiler error? Pin
Colin Angus Mackay3-Jan-06 3:11
Colin Angus Mackay3-Jan-06 3:11 
GeneralRe: Disabling compiler error? Pin
joachimj3-Jan-06 3:14
joachimj3-Jan-06 3:14 
GeneralRe: Disabling compiler error? Pin
J4amieC3-Jan-06 4:06
J4amieC3-Jan-06 4:06 
GeneralRe: Disabling compiler error? Pin
joachimj3-Jan-06 4:21
joachimj3-Jan-06 4:21 
GeneralRe: Disabling compiler error? Pin
J4amieC3-Jan-06 5:18
J4amieC3-Jan-06 5:18 
Questionculture info Pin
PrakashBhaskar2-Jan-06 23:19
PrakashBhaskar2-Jan-06 23:19 
AnswerRe: culture info Pin
S. Akif Kamal3-Jan-06 1:15
S. Akif Kamal3-Jan-06 1:15 
AnswerRe: culture info Pin
Colin Angus Mackay3-Jan-06 2:15
Colin Angus Mackay3-Jan-06 2:15 
GeneralRe: culture info Pin
PrakashBhaskar3-Jan-06 2:19
PrakashBhaskar3-Jan-06 2:19 
QuestionMy app won't run: "unverifiable assembly" Pin
navvara the infantryman2-Jan-06 22:15
navvara the infantryman2-Jan-06 22:15 
AnswerRe: My app won't run: "unverifiable assembly" Pin
mav.northwind3-Jan-06 0:11
mav.northwind3-Jan-06 0:11 
GeneralRe: My app won't run: "unverifiable assembly" Pin
navvara the infantryman3-Jan-06 1:35
navvara the infantryman3-Jan-06 1:35 
GeneralRe: My app won't run: "unverifiable assembly" Pin
J4amieC3-Jan-06 1:43
J4amieC3-Jan-06 1:43 
GeneralRe: My app won't run: "unverifiable assembly" Pin
navvara the infantryman3-Jan-06 1:55
navvara the infantryman3-Jan-06 1:55 
GeneralRe: My app won't run: "unverifiable assembly" Pin
J4amieC3-Jan-06 4:07
J4amieC3-Jan-06 4:07 
AnswerRe: My app won't run: "unverifiable assembly" Pin
leppie3-Jan-06 6:57
leppie3-Jan-06 6:57 
QuestionCan i call the properties window of a specific File from my Application? Pin
shaimaa-galal2-Jan-06 22:02
shaimaa-galal2-Jan-06 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.