Solved

Raise Custom Exception

Posted on 2009-04-05
2
1,870 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 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