raise or throw

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

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
 
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 said:
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'.
 
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
 
Charles Law said:
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


errortext
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
 
Back
Top