Solved

Raise Custom Exception

Posted on 2009-04-05
2
1,871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set arraylist as datatable 2 29
Office 365: Assigning MailboxPlan to a mailbox 8 69
Background worker passing messagebox yes no 13 25
vb.net searchandselect 12 15
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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