Solved

Raise Custom Exception

Posted on 2009-04-05
2
1,867 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
ID: 24074177
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
ID: 24074198
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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: …

932 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

8 Experts available now in Live!

Get 1:1 Help Now