all groups > vb.net upgrade > january 2005 >
You're in the

vb.net upgrade

group:

Replacement for Err.Raise(0)


Re: Replacement for Err.Raise(0) Ken Tucker [MVP]
1/8/2005 3:48:38 AM
vb.net upgrade:
Hi,

Throw an exception.

Throw new Exception("I have an error")

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmThrow.asp

Ken
------------------------------------
[quoted text, click to view]
I need to remove the import of Microsoft.Visualbasic.

Some older .Net code is littered with these.

What is the best practice in this case?

Thanks in advance.


Re: Replacement for Err.Raise(0) Herfried K. Wagner [MVP]
1/8/2005 12:40:49 PM
"Robert" <no@spam.com> schrieb:
[quoted text, click to view]

Exceptions should not be used to control program flow.

[quoted text, click to view]

There is no need to work around the functions included in
"Microsoft.VisualBasic.dll" because they are part of VB.

VB.NET for VB Veterans
<URL:http://msdn.microsoft.com/library/en-us/vbcon/html/vboriintroductiontovisualbasic70forvisualbasicveterans.asp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Replacement for Err.Raise(0) Robert
1/8/2005 2:28:52 PM
I need to remove the import of Microsoft.Visualbasic.

Some older .Net code is littered with these.

What is the best practice in this case?

Thanks in advance.

Re: Replacement for Err.Raise(0) Herfried K. Wagner [MVP]
1/8/2005 3:08:56 PM
Robert,

"Robert" <no@spam.com> schrieb:
[quoted text, click to view]

This gives you more control over imports.

[quoted text, click to view]

In VS.NET, the reference to "Microsoft.VisualBasic.dll" cannot be removed at
all. This is not the case for the command-line complier ("vbc.exe").

[quoted text, click to view]

I remember that some of the functions of 'Microsoft.VisualBasic' are
available for the .NET Compact Framework too and thus can be used in Compact
Framework applications.

[quoted text, click to view]

I would not say that I advocate them, but I see them as part of Visual Basic
that can/should be used whenever it makes sense to use it.

[quoted text, click to view]

Well, it's up to personal preference whether to use the functions or not. I
have chosen to use them in some situations.

[quoted text, click to view]

I think I understand the points you made, but I feel sorry, I am not aware
of a comparison or mapping table between VB's functions and pendants in the
..NET Framework, because IMHO Microsoft doesn't consider using the VB
functions "bad practice".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Re: Replacement for Err.Raise(0) Robert
1/8/2005 5:23:31 PM
I am familiar with exceptions, however throwing an error of 0 is basically
saying there is no error.

In the code it appears it is being used to do a far return to the routine
closest on the call stack, with an error handler.

Perhaps a custom internal exception, that is trapped up the call stack, and
then not re-thrown.

Anyway, I have never used this idiom, and thought this would bean easy one
for this group..

Also, is there a FAQ on how to work around all the functions in
Microsoft.VisualBasic?
I am porting an app to PocketPC, and this library is not supported on that
platform..

Thanks in advance, again.

ps. It is a shame there is not much history in this group.. I think if I
could read messages from 3-4 years ago, all my questions would be answered.
My first visit today, and I saw only 117 messages. And I am in China at the
moment, so Google groups is blocked. Sigh.


[quoted text, click to view]

Re: Replacement for Err.Raise(0) Robert
1/8/2005 9:42:01 PM
inline..

[quoted text, click to view]


Agreed. Not my code.. Did not want to break interfaces.


[quoted text, click to view]

If it is part of VB, why must one Import the namespace (either in each of
your code files) or at the project properties/imports level?
Seems to be an add-on library, and not part of the the VB to IL compiler
process..
Since I can NOT use these functions for a PocketPC port I would love to find
a resource with the common work arounds.

Do you advocate using ANY of the functionality in the Microsoft.VisualBasic
namespace?!? Ever?
I do not use this namespace. I have read numerous articles about the
performance hits, and after all it is just a wrapper around the System
namespaces.

Hope I do not come across as an ass, but it seems you completely missed my
points.

Anyway, if you know of a FAQ the touches on removing this depencency, please
post it. It would prevent me from reinventing the wheel.


Thanks again.

Re: Replacement for Err.Raise(0) Jay B. Harlow [MVP - Outlook]
1/10/2005 8:45:08 PM
Robert,
[quoted text, click to view]
I totally advocate using the functions in the Microsoft.VisualBasic
namespace, especially when using them would "prevent me from reinventing the
wheel".

This does not mean that I use Microsoft.VisualBasic over the other Framework
classes. I use which ever class/method makes the most sense for what I need
done!

For example the Microsoft.VisualBasic.Strings.Split function allows one to
split a string based on words, instead of a single chars that String.Split
does or a pattern that RegEx.Split does. However if I was splitting a string
based on a Char I would use String.Split, likewise if I was splitting a
string based on a Pattern I would use RegEx.Split. 3 functions servicing 3
specific needs.

Same with Microsoft.VisualBasic.Strings.Replace. It has options that
String.Replace, StringBuilder.Replace, and RegEx.Replace do not have.

Remember that a number of the functions in the Microsoft.VisualBasic
namespace are easily used in other languages, such as C#. So if I needed to
split a String based on a word in C#, I would use
Microsoft.VisualBasic.Strings.Split!


Err.Raise(0) sounds like a clever "hack", If there was not a cleaner way to
transfer control I have used custom Exceptions to "get out" of a deeply
nested routine, especially when using functions with a status makes the code
harder to follow rather then easier to follow, and the Exception out is not
the normal flow of control for the routine... However as Herfried suggests
using an Exception to jump out of nested routines, should only be used
exceptional cases...

Hope this helps
Jay

[quoted text, click to view]

AddThis Social Bookmark Button