我想用我在asp.net中编写的下一个代码创建一个帐户
但每当我创建日期时间时,它都会把我扔进catch块,现在我使用了简单的值,如:
DateTime birthdate = new DateTime(1, 2, 2003);
Run Code Online (Sandbox Code Playgroud)
但是当我检查调试器时,它让我脱离了这一行的try块,我真的不明白为什么因为Visual Studio没有给我任何错误所以这里可能出错???
try
{
// male/female check
string sex = "";
if (rbMale.Checked)
{
sex = "Male";
}
else if (rbFemale.Checked)
{
sex = "Female";
}
// birthday
int bdday = Convert.ToInt32(tbBdayDay.Value.ToString());
int bdmonth = Convert.ToInt32(cbBdayMonth.Value.ToString());
int bdyear = Convert.ToInt32(tbBdayYear.Value.ToString());
//this line is pushing me into the catch block!! :(
DateTime birthdate = new DateTime(1, 2, 2003);
// username
string name = tbFirstName.Value.ToString() + " " + tbLastName.Value.ToString();
// fileshare link: www.filesharelink.com/+'username'+'random number'
Random random = new Random();
int randomNumber = random.Next(0, 10001);
string filesharelink = "www.filesharelink.com/" + tbFirstName.Value.ToString() + randomNumber;
// email
string email = tbEmail.Value.ToString();
// password
string password = tbPassword1.Value.ToString();
//returns true if account is succesfully registered
if (administration.query.RegisterAccount(sex, birthdate, name, filesharelink, email, password))
{
ClientScript.RegisterStartupScript(this.GetType(), "titel", "alert('Account created succesfully, you can now log in!');", true);
}
}
catch
{
ClientScript.RegisterStartupScript(this.GetType(), "titel", "alert('Error creating your account, please try again.');", true);
}
Run Code Online (Sandbox Code Playgroud)