M
Mike P
I am trying to create a class where I will validate each parameter sent
to the contructor. I need to know which of the parameters (if any) were
invalid, so do I need to throw a user defined exception at that point so
that I know exactly which parameter had an invalid value?
I am new to creating class objects so I'm unsure about where I should do
my validation and how to trap errors. Here is my code :
private string strCardType;
private string strCardNumber;
public creditcard(string strCardType, string strCardNumber, etc...)
{
try
{
this.CardType = strCardType;
}
catch
{
}
this.CardNumber = strCardNumber;
}
public string CardType
{
get
{
return this.strCardType;
}
set
{
if ((this.strCardType.ToUpper() != "VISA") &&
(this.strCardType.ToUpper() != "MASTERCARD")
&& (this.strCardType.ToUpper() != "SWITCH") &&
(this.strCardType.ToUpper() != "DELTA")
&& (this.strCardType.ToUpper() != "SOLO") &&
(this.strCardType.ToUpper() != "JCB")
&& (this.strCardType.ToUpper() != "VISA ELECTRON") &&
(this.strCardType.ToUpper() != "MAESTRO"))
{
this.strCardType = value;
}
else
{
throw new Exception();
}
}
}
public string CardNumber
{
get
{
return this.strCardNumber;
}
set
{
this.strCardNumber = value;
}
}
Any assistance would be really appreciated.
Cheers,
Mike
to the contructor. I need to know which of the parameters (if any) were
invalid, so do I need to throw a user defined exception at that point so
that I know exactly which parameter had an invalid value?
I am new to creating class objects so I'm unsure about where I should do
my validation and how to trap errors. Here is my code :
private string strCardType;
private string strCardNumber;
public creditcard(string strCardType, string strCardNumber, etc...)
{
try
{
this.CardType = strCardType;
}
catch
{
}
this.CardNumber = strCardNumber;
}
public string CardType
{
get
{
return this.strCardType;
}
set
{
if ((this.strCardType.ToUpper() != "VISA") &&
(this.strCardType.ToUpper() != "MASTERCARD")
&& (this.strCardType.ToUpper() != "SWITCH") &&
(this.strCardType.ToUpper() != "DELTA")
&& (this.strCardType.ToUpper() != "SOLO") &&
(this.strCardType.ToUpper() != "JCB")
&& (this.strCardType.ToUpper() != "VISA ELECTRON") &&
(this.strCardType.ToUpper() != "MAESTRO"))
{
this.strCardType = value;
}
else
{
throw new Exception();
}
}
}
public string CardNumber
{
get
{
return this.strCardNumber;
}
set
{
this.strCardNumber = value;
}
}
Any assistance would be really appreciated.
Cheers,
Mike