Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Catching error on creating a data set
Message
From
12/03/2012 13:53:41
 
 
To
12/03/2012 13:02:24
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01538013
Message ID:
01538090
Views:
30
>>>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 hate using out parameters, seems like a bad design to me.... LOL

I don't find myself using them often either. But I guess it depends on the context. There's not much point in creating a really heavyweight class instance to pass to a method if the method may not be able to do the neccessary work ? e.g.:
MyReallyBigObject reallyBigThing = new MyReallyBigObject();
TryDoingSomething(reallyBigThing);

       void TryDoingSomething(MyReallyBigObject mbo)
        {
            if (SomethingWentWrong) return;
        }
Or where the method returns an array where the array size is determined by the method itself: Only way then:
            MyReallyBigObject[] myArray;
            TryDoingSomething(out myArray);

       void TryDoingSomething(out MyReallyBigObject[] mbo)
        {
            mbo = new MyReallyBigObject[100];
        }
Previous
Reply
Map
View

Click here to load this message in the networking platform