Error Handling code in Excel Based App

  • Thread starter Thread starter Prasun
  • Start date Start date
P

Prasun

Hello:

I am trying to handle exceptions in my code. Here the the code i have


Code:

Dim XLFileConn As New OleDbConnection 'New OleDbConnection object
XLFileConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & filename & _
";Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""" 'New connection
string
Try
Try
XLFileConn.Open() 'Open a connection to the choosen Excel
file
Catch ex As Exception 'Code to detect and handle an exception
generated by a connection error
MessageBox.Show("Connection to File Failed - Invalid File,
File type or Path was chosen.", "File Connection Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error) 'If error
occurs - Display message box alerting user about the error
Exit Sub 'Exit Sub-Routine
End Try





I have built the file including the installer and stuff. I run the program
and try to test the error handling by inputing a pdf file instead of an
excel file, It gives me my message box and after i click OK, it then gives
me a default exception handling dialog box and it gives me a quit or
continue option. Do i need to clear some kind of error flag?

Thank You
Prasun
 
Hi,

If you catch it and show message, then you should not get additional default
messages unless some other exception happened there. I see that you have
nested Try blocks, but since you did not post a full code, it is hard to say
why you get default exception. You also can debug it in a development mode
and do not have to install it to be able to test.
 
I screwed up, I was building it in debug and checking the file from the
release folder.
Thank You for your help

I know have another question but i will put it in a new post

prasun
 
Back
Top