The base class of all the exceptions is
Exception
. When you create your own exception class, you would need to derive from
Exception
or one of its derived classes.
When you handling exceptions, it gets processed sequentially. Thus you need to handle it the way you you have shown
catch (ArgumentNullException)
{
MessageBox.Show("empty text box");
}
catch (FormatException)
{
MessageBox.Show("Please enter only alphanumeric characters", "Input Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
The top most class needs to be the last in your catch block. Otherwise, the derived class below it won't be visible. The way you have the code is ok, and since
(Exception ex)
is your last catch block, as it should be, you don't have any exception at all. If you had any no matter of any exception type, it would have been caught by your last catch block.
So, your source of problem may not be exception.