Click here to Skip to main content
15,912,756 members
Home / Discussions / C#
   

C#

 
GeneralRe: Throwing exception when a property must not be null? Pin
Martin Haesemeyer8-Sep-02 0:39
Martin Haesemeyer8-Sep-02 0:39 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley10-Sep-02 4:50
Paul Riley10-Sep-02 4:50 
GeneralRe: Throwing exception when a property must not be null? Pin
Martin Haesemeyer10-Sep-02 9:56
Martin Haesemeyer10-Sep-02 9:56 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley10-Sep-02 10:10
Paul Riley10-Sep-02 10:10 
AnswerRe: Throwing exception when a property must not be null? Pin
Erik Westermann9-Sep-02 7:43
professionalErik Westermann9-Sep-02 7:43 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley9-Sep-02 9:34
Paul Riley9-Sep-02 9:34 
GeneralRe: Throwing exception when a property must not be null? Pin
Erik Westermann10-Sep-02 4:06
professionalErik Westermann10-Sep-02 4:06 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley10-Sep-02 4:47
Paul Riley10-Sep-02 4:47 
Erik Westermann wrote:
Have you come across the two pronged plugs that plug into the wall only one way? One prong of the plug is keyed and so is the wall receptacle so that the prong must match the wall receptacle's orientation - this is done to prevent something from being plugged in backwards.

Thank god I've been electrocuted enough times in the US to have the faintest idea what you're talking about... our plugs here in the UK are a sensible three-prong design (one vertical, two horizontal) and there's no way on earth anyone's plugging that in the wrong way around! Wink | ;)

Erik Westermann wrote:
The person that designed the plug expected that someone would eventually try to put the plug into the receptacle the wrong way and took measures to ensure the chances of that happening are much smaller than if he did not design the plug with that possibility in mind.

I would argue that this is exactly what the programmer is trying to do in this example. Someone, eventually, is going to pass null to that property and is not going to call IsValid().

Thus the class designer has to check IsValid all over his own class before doing anything with that property and may still have to throw an exception if this causes a situation that is unacceptable. Not only is this inefficient but it's harder for the app programmer to debug.

Erik Westermann wrote:
this is nothing exceptional

I think to a point this is where our opinions part. You are taking "Exception" in the context of "This is an exception to the rule", I think an "Exception" is better described in the context of the program saying "I take exception to this scenario".

Erik Westermann wrote:
Simply becasue the idea of the .NET Platofrm is to provide a space where all activities occur in a managed, type-safe environment. The System namespace is called "system" becuase it exposes classes that you can use to interact with the "system".

If that were true, why are the fundamental base classes all set in the System namespace? Wouldn't Object and Exception be better placed in a "Core" namespace?

However, I do see an argument (although you never quite said this, I think it was your point) that ArgumentNullException is derived from System.SystemException and if someone is trying to catch system-based problems, they will also catch a program defined ArgumentNullException.

That could be a problem, but I would suggest that trying to catch SystemExceptions like this is a problem in and of itself.

For example, RegistryKey.DeleteSubKeyTree will throw an ArgumentNullException if you pass null instead of a string. To argue that this is a system-level exception is ridiculous, just because the registry is part of the system, it must be an application error that caused the problem.

Paul
GeneralRe: Throwing exception when a property must not be null? Pin
Erik Westermann10-Sep-02 15:37
professionalErik Westermann10-Sep-02 15:37 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley11-Sep-02 1:23
Paul Riley11-Sep-02 1:23 
GeneralRe: Throwing exception when a property must not be null? Pin
leppie11-Sep-02 6:32
leppie11-Sep-02 6:32 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley11-Sep-02 7:04
Paul Riley11-Sep-02 7:04 
GeneralRe: Throwing exception when a property must not be null? Pin
leppie11-Sep-02 7:44
leppie11-Sep-02 7:44 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley11-Sep-02 13:26
Paul Riley11-Sep-02 13:26 
GeneralRe: Throwing exception when a property must not be null? Pin
leppie11-Sep-02 16:37
leppie11-Sep-02 16:37 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley11-Sep-02 23:43
Paul Riley11-Sep-02 23:43 
GeneralRe: Throwing exception when a property must not be null? Pin
leppie12-Sep-02 2:08
leppie12-Sep-02 2:08 
GeneralRe: Throwing exception when a property must not be null? Pin
Paul Riley12-Sep-02 2:52
Paul Riley12-Sep-02 2:52 
GeneralRe: Throwing exception when a property must not be null? Pin
leppie12-Sep-02 3:50
leppie12-Sep-02 3:50 
GeneralRe: Throwing exception when a property must not be null? Pin
Martin Haesemeyer10-Sep-02 10:06
Martin Haesemeyer10-Sep-02 10:06 
GeneralRe: Throwing exception when a property must not be null? Pin
Erik Westermann10-Sep-02 15:48
professionalErik Westermann10-Sep-02 15:48 
GeneralRe: Throwing exception when a property must not be null? Pin
jparsons10-Sep-02 5:07
jparsons10-Sep-02 5:07 
GeneralRe: Throwing exception when a property must not be null? Pin
stephen woolhead13-Sep-02 10:48
stephen woolhead13-Sep-02 10:48 
GeneralAdjusting colors Pin
Nnamdi Onyeyiri7-Sep-02 23:49
Nnamdi Onyeyiri7-Sep-02 23:49 
GeneralRe: Adjusting colors Pin
Stephane Rodriguez.8-Sep-02 0:25
Stephane Rodriguez.8-Sep-02 0:25 

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.