Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing try-catch result back to calling form

Posted on 2014-12-05
5
Medium Priority
?
84 Views
Last Modified: 2014-12-06
Hello,

How do I pass the exception from a function in a class back to the calling function on a form?

Dumb Example:

Sub CallingCode

    CallSomeFunction

End Sub

Sub CallSomeFunction
    try
        result = 10/0
    catch
        ' return this exception back to the callingcode function
    end try

End Sub

Open in new window

0
Comment
Question by:prosit
[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
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
prosit earned 0 total points
ID: 40482867
ugh so simple...

Sub CallSomeFunction
    try
        result = 10/0
    catch
        throw ex
    end try

End Sub
0
 
LVL 40
ID: 40484729
I would be surprised if prosit solution worked, because ex has not been defined.

An even if it was, rethrowing a catched exception removes the stacktrace, one of the best piece of information you can have in an exception.

The right way to do it is even simpler, and it keeps all the information intact:

catch
    throw
0
 
LVL 2

Author Comment

by:prosit
ID: 40484748
Hey,

It does work when defining ex but I appreciate you taking the time to show a better way so thank you.

J
0
 
LVL 40
ID: 40484866
To define ex, you would do it the following way:

  try
         result = 10/0
     catch ex As Exception
         throw ex
     end try

This is what you see everywhere, so it is repeated everywhere else. But what I showed you is better because you keep the StackTrace.
0
 
LVL 2

Author Comment

by:prosit
ID: 40484909
Yup, VS does that part for you, I typed it in the editor so I forgot that :)

Thanks again and merry Christmas (or whichever you prefer )
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

705 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