Solved

visual studio 2008 vb.net

Posted on 2012-03-20
4
192 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 166 total points
ID: 37743593
You can throw an exception and the outer catch will catch it.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 167 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 167 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 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