Click here to Skip to main content
15,889,389 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello:
I don't really know how to explain this question.
We are working in a general project where a group works in certain area. My group is working with database and files validators. So far everything is working, but there is one thing we need to add. If the file is in the correct format, it works perfectly. and if the file isn't in the correct format, I catch the error which (also working properly). What we want to do is the following:
I would like to find a way to throw the exception to the User interface group so they can understand my error. Please any ideas on how to do it?? I have done a lot of research and I haven't found anything useful
Posted
Comments
Christian Amado 2-Apr-14 17:03pm    
Any code snippet? What did you try?
BillWoodruff 2-Apr-14 17:35pm    
I suggest you do some search within CodeProject: there are excellent articles on error handling here that will illustrate the type of "re-throw" you will need to do.

i hope the below code snippet helps you

C#
class throwException
{
    System.IO.FileStream logFile = null;
    if (!this.logFile.CanWrite) //this if can be your condition for files correct format
        {
            throw new System.InvalidOperationException("your error message");
        }

}
 
Share this answer
 
Is this what you are looking for?


C#
try
            {
                //try to do something
            }
            catch (Exception ex)
            {
                //if it fails, the code goes here, and ex has a bunch of information about the error
            }
            finally
            {
                //this code runs after the error is thown, it is good for closing files and freeing up resources that you have used.
            }
 
Share this answer
 
Comments
Alexander24 2-Apr-14 17:11pm    
Not really, lets say I catch the exception. How do I sent the exception to the User interface group? How do I let them Know what type of error we have???
stubobis1 2-Apr-14 17:17pm    
well, first you would have to make sure that you know what type you have. Then you would use the throw keyword to throw an exception
-

throw new Exception("User Interface error");
Alexander24 2-Apr-14 17:51pm    
Thank you, I think what to do now. Otherwise, I will be back to the forum
As stated before all you need to do is throw the exception. You can even pass back your own custom error with throw new Exception("your own message.") The UI group will be responsible for calling your code inside of a try catch block so they can catch your exceptions.
 
Share this answer
 
If you are looking for creating and throwing custom exceptions, try -
Custom exceptions in C#.NET[^]
Creating and Throwing Exceptions[^]
 
Share this answer
 
Comments
[no name] 3-Apr-14 1:11am    
please show the code and what type of files (eg:pdf,jpeg,doc) are u going to upload?

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