Solved

Passing try-catch result back to calling form

Posted on 2014-12-05
5
78 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
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
prosit earned 0 total points
Comment Utility
ugh so simple...

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

End Sub
0
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

9 Experts available now in Live!

Get 1:1 Help Now