473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

raise or throw

Hi,
what should I use to raise an error:
RAISE
or
THROW
And I am asking this with regard to the future VB.NET developments. Is Raise
the old way and Throw the new? Throw does not have parms to put errortext in
it, so it seems less usable then raise.
I am looking forward to your opinions.Refs to websites about this are
welcome.
Thanks
Frank
Nov 20 '05 #1
4 4177
Hi Frank

Undoubtedly 'throw'. Strictly, one raises an error and throws an exception.

With throw, you can throw any type of built-in exception, or create you own
and throw that. In either case, you can pass values to the constructor, or
set properties on the new exception, allowing you to pass context or any
other information to the next Try ... Catch block up the stack.

HTH

Charles
"Frank" <fr***@frank.com> wrote in message
news:ca**********@news3.tilbu1.nb.home.nl...
Hi,
what should I use to raise an error:
RAISE
or
THROW
And I am asking this with regard to the future VB.NET developments. Is Raise the old way and Throw the new? Throw does not have parms to put errortext in it, so it seems less usable then raise.
I am looking forward to your opinions.Refs to websites about this are
welcome.
Thanks
Frank

Nov 20 '05 #2
* "Frank" <fr***@frank.com> scripsit:
what should I use to raise an error:
RAISE
or
THROW
And I am asking this with regard to the future VB.NET developments. Is Raise
the old way and Throw the new? Throw does not have parms to put errortext in
it, so it seems less usable then raise.


There is no 'Raise' there is only 'Err.Raise'. 'Throw' can be used to
"rethrow" an exception or to throw a new exception, that is based on
another exception:

\\\
Try
...
Catch e As Exception
Throw New Exception("This is a terrible exception.", e)
End Try
///

I recommend to have a look at the documentation for both, the 'Err'
object and 'Try...Catch' and 'Throws'. For simple tools/"scripts", I
prefer 'Err' because it's more RAD than throws when not using OOP
features, for larger OO applications I prefer 'Throw'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Frank,
In addition to the other comments.

Within VB.NET I would recommend you only Raise events.

That all exceptions be Thrown!

The Throw keyword accepts an Exception object, all Exception objects should
support passing a message (a string) to the Exception's constructor). If you
do not include the Exception object with Throw, the last Caught exception is
thrown, preserving the stack trace.

By creating your own Exception (create a class that inherits from
Exception). You can include extra information in addition to a simple error
text.

Hope this helps
Jay

"Frank" <fr***@frank.com> wrote in message
news:ca**********@news3.tilbu1.nb.home.nl...
Hi,
what should I use to raise an error:
RAISE
or
THROW
And I am asking this with regard to the future VB.NET developments. Is Raise the old way and Throw the new? Throw does not have parms to put errortext in it, so it seems less usable then raise.
I am looking forward to your opinions.Refs to websites about this are
welcome.
Thanks
Frank

Nov 20 '05 #4

"Charles Law" <bl***@nowhere.com> wrote in message
news:OU**************@tk2msftngp13.phx.gbl...
Hi Frank

Undoubtedly 'throw'. Strictly, one raises an error and throws an exception.
With throw, you can throw any type of built-in exception, or create you own and throw that. In either case, you can pass values to the constructor, or
set properties on the new exception, allowing you to pass context or any
other information to the next Try ... Catch block up the stack.

HTH

Charles
"Frank" <fr***@frank.com> wrote in message
news:ca**********@news3.tilbu1.nb.home.nl...
Hi,
what should I use to raise an error:
RAISE
or
THROW
And I am asking this with regard to the future VB.NET developments. Is Raise
the old way and Throw the new? Throw does not have parms to put

errortext in
it, so it seems less usable then raise.
I am looking forward to your opinions.Refs to websites about this are
welcome.
Thanks
Frank


Thanks all, throw it is. But now I have a small problem with the unhandled
errors, I made a handler for it. But before that is executed VB.NET gives me
an error. In VB6 there was a setting (errortrapping) about handling errors
in the design environment and classes, which should prevent the before
mentioned behaviour. Does VB.NET have a setting like it?

Thanks
Frank
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James Stroud | last post by:
Hello All, Is this a bug? Why is this tuple getting unpacked by raise? Am I missing some subtle logic? Why does print not work the same way as raise? Both are statements. Why does raise need to...
2
by: Bogdan Zamfir | last post by:
Hi, I have a problem with err.raise I write a class module, and I want to use this mechanism to indicate errors when user set wrong values to properties But it seems the error is never raised...
3
by: Alan Roberts | last post by:
I havean app written in vb6 that links to a vb6 DLL file. The app handles errors raised by the DLL based on the error number (Err.Number). I would now like to convert the DLL to c#. How can I...
2
by: GS | last post by:
I have noticed that ASP.NET 2.0 writes unhandled exceptions automatically to event log. How do I that on purpouse in a code? Say I have hit error condition and would like to abort current thread and...
6
by: Mr Flibble | last post by:
I have a class that has a LogOn method. I'm trying to think what the advantages are two approaches I have. a) Having a bool returned containing the success of the LogOn. b) Raising an...
3
by: Ramya A | last post by:
This could be a real dumb question but what is the equivalent of VB script's Err.Raise in C#? Thank You Ramya
2
by: bbindae | last post by:
I am trying to check whether XmlTextReader reads the xml file successfully or not. MSDN says that XmlTextReader raise the FileNotFoundException when it cannot find the file to read. Here is...
0
by: RaviRajhulk | last post by:
I am trying to execute a batch file from a perl code and its executing fine with the folowing code Code: ( text ) `C:\temp\sample.bat` ,but another problem is occuring.....when there is some...
9
by: ssecorp | last post by:
Is this correct use of exceptions? to raise an indexerror and add my own string insetad of just letting it raise a IndexError by itself and "blaming" it on list.pop? class Stack(object): def...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.