Dealing with exception in a Form Load event

Posts   
 
    
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 20-Aug-2008 15:17:28   

Hello, I used to write such code :

try
{
        myForm.ShowDialog()
}
catch(SocketException ex)
{
       //show a friendly error message here like : "Service is currently unavailable"
}


//MyForm load event
private void myForm_Load( sender, EventArgs)
{
        ManagerClass.GatherSomeDataByRemoting(); //method which may throw a SocketException
}

It's a newbie error you all would probably laugh at... I have just figured out that in case a SocketException would occur during the form load method, the code would simply return without actually triggering my catch block, allowing the form to show itself in an unexpected state.

From what I understand, it's because a Form load event isn't actually triggered by ShowDialog or doesn't execute on the same stack. It's ok, but I wonder if there are nice ways to propagate exceptions that occur in a load event so that they aren't just swept under the rug?