Click here to Skip to main content
16,005,552 members
Home / Discussions / C#
   

C#

 
GeneralRe: Available Controls Pin
Mazdak8-Sep-02 10:34
Mazdak8-Sep-02 10:34 
QuestionThrowing exception when a property must not be null? Pin
Martin Haesemeyer7-Sep-02 23:56
Martin Haesemeyer7-Sep-02 23:56 
AnswerRe: Throwing exception when a property must not be null? Pin
Paul Riley8-Sep-02 0:33
Paul Riley8-Sep-02 0:33 
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 
Exceptions are for exceptional conditions - conditions that are unexpected during normal circumstances. Exceptions are relatively expensive and aren't that great for stuff like this.

I personally would write the class to have a constructor that accepts all required arguments in addition to returning an error (or true/false) on execution of a method that finds a required field that contains null. Perhaps go as far as exposing a public read-only IsValid property and have your internal methods call it - exposing IsValid may also help developers understand how your class works since they can check the object's validity anytime they like.

If you insist on using exceptions, don't throw CLR exceptions(like System.ArgumentNullException - these are CLR-sourced exceptions. You can create your own application-specific exceptions based on the System.ApplicationException class - it exists for people like us to create our own exceptions. Just create your own class and derive it from System.ApplicationException - you don't have to add any members since the catch statement works based on the exception's type.


Erik Westermann
Author, Learn XML In A Weekend (October 2002)

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

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.