Results 1 to 3 of 3

Thread: Control Exception Message

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    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:
    1. Try
    2.             oExcel.Workbooks.Open(Filename:=m_inFile)
    3.             Try
    4.                 oSht = CType(oExcel.Workbooks(1).Worksheets("control"), Excel.Worksheet)
    5.             Catch ex As Exception
    6.  
    7.             End Try
    8.             If oSht Is Nothing Then
    9.                 Throw New System.Exception("Invalid Template Format: No Control Sheet")
    10.             End If
    11.             oExcel.Visible = m_visible
    12.         Catch ex As Exception
    13.             MessageBox.Show("TemplateReader.Open: " & ex.Message.ToString)
    14.         End Try

  2. #2
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    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
  •  



Click Here to Expand Forum to Full Width