Click here to Skip to main content
14,211,925 members
Rate this:
Please Sign up or sign in to vote.
hi, i write a C# program (Windows form) that work online , but many exceptions appears because of slow internet.
how to override all connection exceptions (Throughout the program(with another custom msg and show C# MessageBox.Show.

What I have tried:

i tried throw custom exception like this , but i want to write class that affect on all the program and appear automatically if any connection exceptions occurs.

            newStudent = new Student();
            newStudent.StudentName = "James007";
        catch(InvalidStudentNameException ex)
            Console.WriteLine(ex.Message );
Updated 16-May-19 9:40am
phil.o 16-May-19 8:29am
If there are so many exceptions, are you sure you want to materialize each of them in its own messagebox? From the point of view of the user, this could turn into a nightmare very quickly.
Golden Basim 16-May-19 12:26pm
same exception but it appear many times , so i want to replace it with a custom msgbox , user see this exception and think that the program was crashed
Richard MacCutchan 16-May-19 9:40am
Put the try/catch block at the top level of your application. You can then check for specific exception types and act accordingly.
Golden Basim 16-May-19 12:27pm
the exception maybe appear in the loading of the program , and maybe appear during the work
Richard MacCutchan 16-May-19 12:33pm
You need to find out what types of exceptions they are, and what cause them. It mat be that there is some action you can take to continue the application.
Golden Basim 16-May-19 12:47pm
yes i know , i just want to avoid repeating catch statement in every code and every window
Richard MacCutchan 17-May-19 3:52am
If you need to do that then there is something wrong with your design.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190619.2 | Last Updated 16 May 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100