Results 1 to 3 of 3

Thread: How to catch error from class and stop from loading

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    4
    Rep Power
    0

    How to catch error from class and stop from loading

    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

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,956
    Rep Power
    151
    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.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    May 2018
    Posts
    4
    Rep Power
    0
    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 thrownew System.ArgumentException?

    Thank you,

Similar Threads

  1. Error loading datagridview...
    By cboshdave in forum Windows Forms
    Replies: 1
    Last Post: 06-15-2017, 11:07 PM
  2. Briefly explaining Try...catch...finally?
    By VitzzViperzz in forum C# General Discussion
    Replies: 2
    Last Post: 04-30-2017, 8:06 PM
  3. console to stop and stay up
    By old_man in forum Console Application
    Replies: 3
    Last Post: 11-08-2016, 10:09 PM
  4. stop process
    By jassie in forum C# General Discussion
    Replies: 1
    Last Post: 02-16-2013, 7:32 PM
  5. stop program and release resources
    By jassie in forum C# General Discussion
    Replies: 4
    Last Post: 02-08-2013, 1:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •