473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB.NET 2005 Exception Handling

Background:
The Program runs a query on a SQL Database, then it takes the gathered information and outputs it into an excel document and saves it to a specified location.

Problem:
I currently have a check in the Form1_Load that checks to make sure the Program is not being run from a network location. It does this by trying to create Folders on a network drive. If the program is stored on the network drive and it tries to create the folders it throws a System.Security.SecurityException. Currently the way it is set up after it tries to create the folders and throws an exception, the exception is caught and a MsgBox is displayed notifying the user that the program can’t be run from a network location. The Problem lies in the fact that after it displays that box and the user clicks ok it displays a Microsoft .Net Framework Dialog Box. The Box says “Application attempted to perform an operation not allowed by the security policy.” The box gives the options of Details, Continue and Quit. If you click Quit…it quits, like it should. If you click Continue it opens the Program anyways. In the Catch it says to display the MsgBox and exit the program.

Question:
How can I make it not Display the dialog box? Or how can I make it quit before it displays the dialog box? Also I probably did this Try, Catch and Throw Incorrectly, so how do I correctly write this?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         ' Check to make sure Program is being run locally
  3.         Try
  4.             ' Create file directory
  5.             createDirectories()
  6.         Catch ex As System.Security.SecurityException
  7.             MsgBox("You can not open this Program from" & (vbCr) & "A network Location.", 0 + 48, "Portal Error")
  8.             End
  9.         End Try
  10.  
  11.     ' More Code after this but it is unnecessary to this problem
  12. End Sub
  13.  
  14.     Private Sub createDirectories()
  15.         Dim i As Integer
  16.         For i = 0 To 2
  17.             Try
  18.                 If i = 0 Then
  19.                     MkDir("U:\Portal\")
  20.                 End If
  21.                 If i = 1 Then
  22.                     MkDir("U:\Portal\Aesop\")
  23.                 End If
  24.                 If i = 2 Then
  25.                     MkDir("U:\Portal\Reports\")
  26.                 End If
  27.             Catch ex As Exception
  28.                 Exit Try
  29.             End Try
  30.         Next
  31.     End Sub
  32.  
Comments:
Thank you for any help you have to offer me. If you need any more explanation to help or more code just let me know.

This is not a School Project, I am creating this program for the company I work for and I am trying to fine tune the program before I release it.
Oct 24 '07 #1
0 1324

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
0
by: Ralph Wheaton | last post by:
I have an Windows Forms application written in 2005 August CTP in which we are standardizing exception handling. All forms inherit from one form, so I have placed all exception handling code in...
9
by: Hasani \(remove nospam from address\) | last post by:
I was reading a ppt ( http://www.gotdotnet.com/team/pdc/4064/tls310.ppt ) and came aross this statement. "Users can leverage a destructor. The C++ compiler generates all the Dispose code...
11
by: ahammad | last post by:
When using the try catch block in Visual Studio 2005, we cannot have: try{ } catch (...) {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.