Default Exception Value

B

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
 
H

Herfried K. Wagner [MVP]

bh said:
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.
 
J

Jay B. Harlow

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top