Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Catching error on creating a data set
Message
 
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01538013
Message ID:
01538060
Views:
29
>>Hi,
>>
>>I am working on creating a good error-catching approach for the following scenario:
>>
>>The UI of the ASP.NET calls a method of a class that is supposed to return a DataSet. Let's call this class and method DataAccess.GetDataSet(). Inside the method GetDataSet I have Try Catch. If there is a problem I can get the error description from the exception caught with Catch. But how do I notify the calling routine that there was problem creating the dataset? The GetDataSet is supposed to return dataset and not a string.
>>
>>TIA for any suggestions.
>
>IMO, unless you have a very good reason not to, I'd just rethrow the exception. Any other solution will depend on the calling routine knowing that it must check for success/failure and there is not guarantee that that will happen.
>
>Otherwise you could use John's suggestion. Or have the method return a bool and use a ref or out parameter for the dataset. Or use a tuple. Or.....

I solved the problem as following (and since I didn't quite understand what John suggested it could be the same or not).

The calling routine creates a variable string ErrorMessage. This variable is passed as Out to the method that creates the data set. If the code fails to connect to the server or whatever else the problem, the ErrorMessage gets a value of exception message (e.message) from the try - catch. And the data set is assigned a value of null.
Then calling routine can check if the data set is null or not null. And if null, shows the error message string ErrorMessage.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform