?
Solved

visual studio 2008 vb.net

Posted on 2012-03-20
4
Medium Priority
?
204 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 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

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…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 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