Question How to catch error from class and stop from loading

SankaUD

Member
Joined
May 17, 2018
Messages
19
Programming Experience
1-3
Hi All,

I have a class dedicated to reading file contents and I want my MDI child from to stop loading (say when the user opens the file from file menu) if this class throws an exception (ie. file contains a null value). how can this be done?

If there is a easy way, I can catch all errors occurs in my class and terminate MDI child from from loading.

I am not a C# expert hope someone can help me.

Thanks
 
If you don't want to display the form then don't call its Show method. Try to pen the file before that, either in the calling form or in the form constructor, and then don't call Show if that fails.
 
Hi jmcilinney,

Thanks for the reply but I quite don't understand this. say I have the following.

User Clicks the MDI parent menu to open the file. And file link is passed to Class to read it's content and error checking.

Class finds an issue with the file and then wants to terminate loading of MDI child related to that file.

I wan gonna create Throw exception in the class and capture this form show event.

Can you please give an example of how this can be done? is it ok to use throw new System.ArgumentException?

Thank you,
 
Back
Top Bottom