|
-
Apr 24th, 2007, 01:15 PM
#1
Thread Starter
Hyperactive Member
Control Exception Message
I'm opening an Excel template and checking the format of the template. If the format is not correct I want to send the appropriate message. I got it to work but it seems like a excessive use of try-catch. Is there a better way?
vb Code:
Try
oExcel.Workbooks.Open(Filename:=m_inFile)
Try
oSht = CType(oExcel.Workbooks(1).Worksheets("control"), Excel.Worksheet)
Catch ex As Exception
End Try
If oSht Is Nothing Then
Throw New System.Exception("Invalid Template Format: No Control Sheet")
End If
oExcel.Visible = m_visible
Catch ex As Exception
MessageBox.Show("TemplateReader.Open: " & ex.Message.ToString)
End Try
-
Apr 24th, 2007, 01:31 PM
#2
Re: Control Exception Message
Actually, there is nothing wrong with nested Try/Catch blocks. However, in your case, your inner Try/Catch isn't doing anything on error, is that intentional?
-
Apr 24th, 2007, 01:57 PM
#3
Thread Starter
Hyperactive Member
Re: Control Exception Message
However, in your case, your inner Try/Catch isn't doing anything on error, is that intentional?
It was. That was the only way that I could get the message that I wanted. I let the exception thrown by Excel fall through the cracks then throw my exception that describes what really happend.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|