Solved

visual studio 2008 vb.net

Posted on 2012-03-20
4
189 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 33

Expert Comment

by:paulmacd
Comment Utility
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 166 total points
Comment Utility
You can throw an exception and the outer catch will catch it.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 167 total points
Comment Utility
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 167 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now