?
Solved

visual studio 2008 vb.net

Posted on 2012-03-20
4
Medium Priority
?
219 Views
Last Modified: 2012-03-20
If while inside a try ... catch, a second try...catch is run, is there a way to communicate to the original try...catch that an error occured while inside the other try...catch?

EXAMPLE:
a try...catch is running that opens up a report.  The report has an error attempting to get data from SQL.  The try...catch inside the report correctly exits the report without issue and control moves back to the original try...catch.  The original try...catch has no idea the try...catch in the report caught an error.
0
Comment
Question by:dastaub
4 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37743589
You could set a flag of some sort, and handle that in code.  Otherwise, as far as the outer Try...Catch is concerned, the no error took place (because it was caught).
0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 664 total points
ID: 37743593
You can throw an exception and the outer catch will catch it.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 668 total points
ID: 37743600
You can throw the exception when it is caught in the inner try block and it will then be bubbled up to the outer try block with all info intact.

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Try
            Try
                'Exception happens here
                Throw New Exception("Hello world")
            Catch ex As Exception
                Throw  'Just throw... 
            End Try

        Catch ex As Exception

            ''handle when caught here
            MsgBox(ex.Message)

        End Try
    End Sub
End Class

Open in new window

0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 668 total points
ID: 37743618
Throw the exception using the throw keyword and the outer try..catch will trap it.
Try 
----
    Try
      ----
    Catch ex as exception
        throw
    End Try
Catch ex as exception
  ----
End Try

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 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