HighTechTalks DotNet Forums  

Replacement for Err.Raise(0)

VB.net Upgrade microsoft.public.dotnet.languages.vb.upgrade


Discuss Replacement for Err.Raise(0) in the VB.net Upgrade forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Robert
 
Posts: n/a

Default Replacement for Err.Raise(0) - 01-08-2005 , 12:28 AM






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.



Reply With Quote
  #2  
Old   
Ken Tucker [MVP]
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-08-2005 , 02:48 AM






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
------------------------------------
"Robert" <no (AT) spam (DOT) com> wrote

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.




Reply With Quote
  #3  
Old   
Robert
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-08-2005 , 03:23 AM



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.


"Ken Tucker [MVP]" <vb2ae (AT) bellsouth (DOT) net> wrote

Quote:
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
------------------------------------
"Robert" <no (AT) spam (DOT) com> wrote in message
news:eEZ$1rU9EHA.2788 (AT) TK2MSFTNGP15 (DOT) phx.gbl...
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.






Reply With Quote
  #4  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-08-2005 , 05:40 AM



"Robert" <no (AT) spam (DOT) com> schrieb:
Quote:
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.
Exceptions should not be used to control program flow.

Quote:
Also, is there a FAQ on how to work around all the functions in
Microsoft.VisualBasic?
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/vboriintroductiontovisualbasic70forvisualbasicvete rans.asp>

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



Reply With Quote
  #5  
Old   
Robert
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-08-2005 , 07:42 AM



inline..

"Herfried K. Wagner [MVP]" <hirf-spam-me-here (AT) gmx (DOT) at> wrote

Quote:
"Robert" <no (AT) spam (DOT) com> schrieb:
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.

Exceptions should not be used to control program flow.

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


Quote:
Also, is there a FAQ on how to work around all the functions in
Microsoft.VisualBasic?

There is no need to work around the functions included in
"Microsoft.VisualBasic.dll" because they are part of VB.
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.




Reply With Quote
  #6  
Old   
Herfried K. Wagner [MVP]
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-08-2005 , 08:08 AM



Robert,

"Robert" <no (AT) spam (DOT) com> schrieb:
Quote:
Also, is there a FAQ on how to work around all the functions in
Microsoft.VisualBasic?

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

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?
This gives you more control over imports.

Quote:
Seems to be an add-on library, and not part of the the VB to IL compiler
process..
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").

Quote:
Since I can NOT use these functions for a PocketPC port I would love to
find a resource with the common work arounds.
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.

Quote:
Do you advocate using ANY of the functionality in the
Microsoft.VisualBasic namespace?!? Ever?
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.

Quote:
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.
Well, it's up to personal preference whether to use the functions or not. I
have chosen to use them in some situations.

Quote:
Hope I do not come across as an ass, but it seems you completely missed my
points.
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/>



Reply With Quote
  #7  
Old   
Jay B. Harlow [MVP - Outlook]
 
Posts: n/a

Default Re: Replacement for Err.Raise(0) - 01-10-2005 , 08:45 PM



Robert,
Quote:
Do you advocate using ANY of the functionality in the
Microsoft.VisualBasic namespace?!? Ever?
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

"Robert" <no (AT) spam (DOT) com> wrote

Quote:
inline..

"Herfried K. Wagner [MVP]" <hirf-spam-me-here (AT) gmx (DOT) at> wrote in message
news:OknwmbX9EHA.2192 (AT) TK2MSFTNGP14 (DOT) phx.gbl...
"Robert" <no (AT) spam (DOT) com> schrieb:
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.

Exceptions should not be used to control program flow.


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


Also, is there a FAQ on how to work around all the functions in
Microsoft.VisualBasic?

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

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.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.