Solved

Raise Custom Exception

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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