Solved

Raise Custom Exception

Posted on 2009-04-05
2
1,866 Views
Last Modified: 2012-05-06
Hi,

In VB.NET, how can I raise custom exceptions? I am trying to doing something like

Try
    ...
    If FileNotFound Then
        Raise exFileNotFound(strFilename)
    End If
...

I would then expect to see the error message "The file xxxstrFilenamexxx was not found."

0
Comment
Question by:NicksonKoh
2 Comments
 
LVL 9

Expert Comment

by:Hawkvalley1
Comment Utility
Just use the MsgBox to display a message when the file is not found:



If New FileInfo(strFilename).Exist Then

   ' do something

Else

   MsgBox("The File " & strFilename & " was not found!")

End If

Open in new window

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
Comment Utility
Just use the "Throw" keyword:
http://msdn.microsoft.com/en-us/library/xhcbs8fz.aspx
http://msdn.microsoft.com/en-us/library/48ca3hhw.aspx

Something like:

    If FileNotFound Then
        Throw New Exception("The file " & strFilename & " was not found.")
    End If

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Converting C# Objects into JSON file 7 36
Round up to 100% in .NET 10 39
Create XML 5 30
Copy/Clone an object. 9 10
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now