Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to raise an exception in VB.NET

How should an exception be raised in VB.NET?

like image 841
CJ7 Avatar asked Oct 31 '12 04:10

CJ7


People also ask

How do you raise a new exception?

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.

How do I manually raise exceptions?

Throwing exceptions manually To throw an exception explicitly you need to instantiate the class of it and throw its object using the throw keyword.

What is throw in VB net?

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.


1 Answers

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.") 
like image 147
Adriaan Stander Avatar answered Oct 07 '22 02:10

Adriaan Stander