method parameters & byRef.

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi

When I create a method in vb.net, I can specify that the parameters passed are byVal or byRef. I tend to use the byRef when I want to return an error code if an exception is caught.

My question therefore is:
1. Is the use of byRef for passing error codes the correct approach? or is there a more effective approach especially if my functionis designed to return say a dataset?

Mike55.
 
The best way to signal an error is just by using exceptions. If the routine you are calling has handled the error why does the calling routine need to know?
If on the other hand the called routine isn't handling the exception then it shouldn't be catching it.

As a rule you should use parameters for passing information into a routine and a return value for returning a result. If there is an unhandled error then signal this by either throwing an exception or just allowing the exception to propagate up the call stack.
 
Back
Top