我有一些正在被正確觸發的代碼,雖然它看起來並沒有真正做我期望它應該做的事情。異常不停止應用程序
我使用System.Text.RegularExpressions.Regex來測試正確格式化的方法參數,在我的測試中,我拋出的ArgumentException實際上並沒有停止應用程序。而且它也沒有嘗試/抓住它。
當我遍歷我的代碼時,看起來只要它碰到throw new ArgumentException
行,就會跳轉到我的Form1_Activated事件處理程序,然後繼續執行其業務。
void MainForm_Load(object sender, System.EventArgs e)
{
SNSBackup.Backup(_saveLocation, _saveLocation + "\\Backups", "*.xml, *.recipex", 5, ArchiveType.Zip);
}
public static void Backup(string source, string destination, string ext, int backupsToKeep, ArchiveType type)
{
// Test to see if the 'ext' parameter is in a valid format.
// Makes sure that the
Regex r = new Regex(@"^(\*\.\w+\s*\,?\s*)+$");
if (!r.IsMatch(ext))
throw new ArgumentException();
您是否運行64位版本的Windows? – 2012-01-12 15:33:01
您可能會在這裏找到您的答案:http://stackoverflow.com/questions/1409161/exceptions-ignored-in-form-load-for-x64 – 2012-01-12 15:36:51