這是如此混亂...... 我有一組類,在這裏獲得方法是其中的幾個:未處理的異常錯誤C#
public string Naziv
{
get { return naziv; }
set
{
naziv = value;
if (naziv == "")
{
throw new Exception("Morate uneti naziv radnog mesta.");
}
else if (naziv.Length < 5)
{
throw new Exception("Naziv mora biti duzi od 5 karaktera.");
}
}
}
這一個完美的作品。但是,這一個:
public string RadnoVreme1
{
get { return radnovreme1; }
set
{
radnovreme1 = value;
if (IsValid(radnovreme1) == false)
{
//Console.WriteLine("1:FALSE ");
throw new Exception("Radno vreme mora biti u formatu '12:00h-20:00h'.");
}
}
}
static bool IsValid(string value)
{
return Regex.IsMatch(value, @"^\d{2}:\d{2}h-\d{2}:\d{2}h");
}
打破我的解決方案有一個錯誤:
An unhandled exception of type 'System.Exception' occurred in Evidencija.exe Additional information: Radno vreme mora biti u formatu '12:00h-20:00h'.
另一件事。當取消註釋「Console.WriteLine
」線和註釋掉「throw new Exception
」一個我得到這樣的輸出:
1:FALSE
1:FALSE
1:FALSE
The thread 0x1748 has exited with code 0 (0x0).
這是爲什麼呢運行3次?是否因爲我的數據庫中已經有3個存儲的對象?不應該只在創建新對象時才運行?
好像你在某處設置了4次RadnoVreme1。嘗試使用斷點逐步執行代碼? – Striker