prosit
asked on
Passing try-catch result back to calling form
Hello,
How do I pass the exception from a function in a class back to the calling function on a form?
Dumb Example:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey,
It does work when defining ex but I appreciate you taking the time to show a better way so thank you.
J
It does work when defining ex but I appreciate you taking the time to show a better way so thank you.
J
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.
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.
ASKER
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 )
Thanks again and merry Christmas (or whichever you prefer )
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