C# Exception Catching

Shovel

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,350
Hello all, just a quick issue over exception handling.

I've got a simple Postcode control - a text box that validates against a postcode regular expression as you type and responds accordingly. I have two implementations, one which changes the colour of the control internally and another which throws a custom exception - the idea being that the exception can then be caught by the parent application and handled in some custom manner.

Problem, I can't get the catching right.
Code:
        static void Main() {
            try {
                Application.Run(new Form1());
            }
            catch(PostCodeDLL.InvalidPostCodeFormatException e) {
                MessageBox.Show("InvalidPostCodeFormatException Caught!");
            }    
        }

Dead simple implementation at the moment (since I just want to make it work). However, while the exception is caught correctly, the application exits immediately after the MessageBox is closed. I don't know if I need to use some other exception type, or if I need to somehow interrupt the application closing, but I don't know how to do either, so some help would be greatly appreciated.

Thanks,

Ben
 

Shovel

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,350
Thanks Dave...

It's alright, I'm going to re-implement it using an event rather than an exception, that ought to work better :)
 

Users who are viewing this thread

Top Bottom