473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

use of exceptions or compolex classes instead of parameters by ref

When I am designing a method that returns a value of a certain type (say Type1) and then occassionally has to return value of certian other type (say Type2), I can design the method in the following ways (I am not sure if there are more ways).
1.. Type1 foo(ref Type2 x){ //populate x occassionally}
2.. Type1 foo(){//throw an instance of Type2 instead of populating a ref parameter}
3.. Type3 foo(){} //where Type3 is a class that encapsulates a variable of Type1 and a variable of Type2
Which one is better or more elegant and why?
My initial take on this considering that the exception handling in .NET is expensive is that,

If returning a Type2 is very rare then implement use method 2 (using exception handling) and otherwise use method 3.
Especially languages such as Java do not have pass by ref (they do have reference types pass by val) so I was wondering if method 1 is less elegant or less preferred as far as good design goes.
TIA
Sankar Nemani
Nov 16 '05 #1
2 937
"Sankar Nemani" <sn*****@nospamlumedx.com> wrote:
[returning Type1 or Type2]


Your return type should not be a big mystery. Making your return type
inherit from Exception and "throwing" it seems quite insane. What are
you trying to do here?

P.
Nov 16 '05 #2
Hi Sankar,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know the best way to return
an object. If there is any misunderstanding, please feel free to let me
know.

I think the best way to do this is to use the return value. Return value is
the most elegant way. However, if you have several objects to return, you
can try to use both return value and a reference parameter.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
by: Steven Bethard | last post by:
I feel like this has probably been answered before, but I couldn't find something quite like it in the archives. Feel free to point me somewhere if you know where this has already been answered. ...
5
by: John | last post by:
Hi, In my years as a VB programmer, I have settled into this pattern of creating collections classes, with an AddNew() method. AddNew() validates the parameters, instantiates the object, adds...
5
by: Dave | last post by:
Hello all, Unfortunately, the reference I have is a bit slim on describing how to create user-defined exceptions derived from std::exception. I think what I have below will work, but is it the...
15
by: Bernard | last post by:
Hi All, I am not sure if I should be asking this question on clc or clc++. Let me try on both. I hope that this is not too trivial for the brilliant minds over here. I know that OOP questions...
10
by: Razzie | last post by:
Hi all, The title of this post may sound a bit weird, but I was wondering about the following nonetheless. I have a class libray containing, say, 4 classes: A, B, C, D. Class A somehow has a...
4
by: John | last post by:
I have WSDL file with <wsdl:fault> element. When I use Websphere WSAD to generate Java proxy classes from WSDL, I am able to see the custom exception classes that correspond to the <wsdl:fault>...
4
by: a_agaga | last post by:
Hi! Do you know different alternatives to convert exceptions in many methods of some wrapper classes. User -Wrapper classes -LibraryClasses -... Wrapper classes catch an exception of only...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.