Solved

visual studio 2008 vb.net

Posted on 2012-03-20
4
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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