Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

try
        {               
            newStudent = new Student();
            newStudent.StudentName = "James007";
            
            ValidateStudent(newStudent);
        }
        catch(InvalidStudentNameException ex)
        {
            Console.WriteLine(ex.Message );
        }
Posted
Updated 16-May-19 9:40am
Comments
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.

1 solution

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900