By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

Default Exception Value

P: n/a
bh
Is there such thing as a default exception value? I'm trying to pass an
optional parameter, containing an exception back to a calling procedure. In
the pseudocode, below, what might I put in place of the ??? in the calling
procedure & corresponding function? Thanks in advance. BH

CALLING PROCEDURE:
Dim ex as exception
ex = ???
GetPossibleException(ex)
Public Function GetPossibleException(optional ByRef ex as exception = ???)
as datareader
Try
..
..
..
Return MyDataReader

Catch MyExc as Exception
ex = MyExc
End Try
Nov 15 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"bh" <No****@ReplyToGroup.comschrieb:
Is there such thing as a default exception value? I'm trying to pass an
optional parameter, containing an exception back to a calling procedure.
In the pseudocode, below, what might I put in place of the ??? in the
calling procedure & corresponding function? Thanks in advance. BH

CALLING PROCEDURE:
Dim ex as exception
ex = ???
GetPossibleException(ex)
Public Function GetPossibleException(optional ByRef ex as exception = ???)
This won't work because 'Exception' is a reference type and specifying a
custom default value when using 'Optional' only works for certain value
types and strings. You may want to use overloading instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 15 '06 #2

P: n/a
bh,
In addition to the other comments.

There is only one available default value for reference types other then
String. Nothing. literally.
Public Function GetPossibleException(optional ByRef ex as exception =
Nothing) as datareader
If you want a default other then Nothing, then consider overloading as
Herfried suggests:
Public Function GetPossibleException() as datareader
Return GetPossibleException(New Exception())
End Function
Public Function GetPossibleException(ByRef ex as exception) as datareader
HOWEVER! Why would you pass a default to a ByRef parameter that you are
returning a value to?

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"bh" <No****@ReplyToGroup.comwrote in message
news:ur**************@TK2MSFTNGP04.phx.gbl...
Is there such thing as a default exception value? I'm trying to pass an
optional parameter, containing an exception back to a calling procedure.
In the pseudocode, below, what might I put in place of the ??? in the
calling procedure & corresponding function? Thanks in advance. BH

CALLING PROCEDURE:
Dim ex as exception
ex = ???
GetPossibleException(ex)
Public Function GetPossibleException(optional ByRef ex as exception = ???)
as datareader
Try
.
.
.
Return MyDataReader

Catch MyExc as Exception
ex = MyExc
End Try
Nov 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.