How should an exception be raised in VB.NET?
The raise keyword is used to raise an exception. You can define what kind of error to raise, and the text to print to the user.
Throwing exceptions manually To throw an exception explicitly you need to instantiate the class of it and throw its object using the throw keyword.
You can use the Throw statement to trap errors within your code because Visual Basic moves up the call stack until it finds the appropriate exception-handling code.
You would throw a new exception.
Have a look at Throw Statement (Visual Basic)
The Throw statement throws an exception that you can handle with structured exception-handling code (Try...Catch...Finally) or unstructured exception-handling code (On Error GoTo). You can use the Throw statement to trap errors within your code because Visual Basic moves up the call stack until it finds the appropriate exception-handling code.
EDIT
By request and from the link
Throw New System.Exception("An exception has occurred.")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With