I've got a bit of code that is being properly triggered, though it seems it's not actually doing what I expect it should be doing.
I'm using System.Text.RegularExpressions.Regex to test a method parameter for proper formatting, and in my tests, the ArgumentException I'm throwing isn't actually halting the application. And there is no try/catch around it either.
When I step through my code, it appears that as soon as it hits the throw new ArgumentException
line, it jumps to my Form1_Activated event handler, and then continues on with its business.
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();