Hello,
I have a module which has the flow as follows
Private sub trysomething()
Try
if something....
... some code
if something
dim x as new clsX()
call x.func(parm1)
dim y as new clsY()
call y.func(parm2)
else
dim x as new clsX()
call x.func(parm2)
dim y as new clsY()
call y.func(parm2)
end if
end if
catch ex as exception
msgbox = ex.message
end try
end sub
if in module class clsX - func: I also have try catch block. This try catch
does catch an error, however, it is never passed up to the trysomething
subroutine? How come? Is it because of the nested IF's? This means thet
y.func is getting called even though an error did occur and was caught in
x...
How can I fix this correctly so that if an error occurs in X, the main
trysomething Catch is triggered?
Thanks!
Jim 7 1231
* "James Radke" <jr*****@wi.rr. com> scripsit: I have a module which has the flow as follows
Private sub trysomething() Try
if something.... ... some code
if something dim x as new clsX() call x.func(parm1) dim y as new clsY() call y.func(parm2) else dim x as new clsX() call x.func(parm2) dim y as new clsY() call y.func(parm2) end if end if
catch ex as exception msgbox = ex.message end try
end sub
if in module class clsX - func: I also have try catch block. This try catch does catch an error, however, it is never passed up to the trysomething subroutine? How come? Is it because of the nested IF's? This means thet y.func is getting called even though an error did occur and was caught in x...
You will have to rethrow the error by calling 'Throw' in order to be
able to catch it.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
What do you mean by "rethrow"?
Will I need Try/catches within the If-then-elses?
Jim
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:bp******** *****@ID-208219.news.uni-berlin.de... * "James Radke" <jr*****@wi.rr. com> scripsit: I have a module which has the flow as follows
Private sub trysomething() Try
if something.... ... some code
if something dim x as new clsX() call x.func(parm1) dim y as new clsY() call y.func(parm2) else dim x as new clsX() call x.func(parm2) dim y as new clsY() call y.func(parm2) end if end if
catch ex as exception msgbox = ex.message end try
end sub
if in module class clsX - func: I also have try catch block. This try
catch does catch an error, however, it is never passed up to the trysomething subroutine? How come? Is it because of the nested IF's? This means
thet y.func is getting called even though an error did occur and was caught
in x...
You will have to rethrow the error by calling 'Throw' in order to be able to catch it.
-- Herfried K. Wagner [MVP] <http://www.mvps.org/dotnet>
* "James Radke" <jr*****@wi.rr. com> scripsit: What do you mean by "rethrow"?
Will I need Try/catches within the If-then-elses?
You will have to remove the error handler from the procedure you are
calling inside the 'If...Then' and/or throw the catched exception using
'Throw' _inside_ the procedure.
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
"James Radke" <jr*****@wi.rr. com> schrieb [code]
if in module class clsX - func: I also have try catch block. This try catch does catch an error, however, it is never passed up to the trysomething subroutine? How come?
If you catch the error in func, it is already caught. Only if there's no
Try..catch in func, the exception is handled in sub trysomething.
--
Armin
http://www.plig.net/nnq/nquote.html
http://www.netmeister. org/news/learn2quote.htm l
I was under the impression that if you use:
#1) try...
catch
end try
versus
#2 try
catch ex as exception
end try
that the error would be caught, processing halted, AND the exception passed
up to the calling routine... Only if you use #2 would the exception be
fully handled in the routine.. is that not correct?
Jim
"Armin Zingler" <az*******@free net.de> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. "James Radke" <jr*****@wi.rr. com> schrieb [code]
if in module class clsX - func: I also have try catch block. This try catch does catch an error, however, it is never passed up to the trysomething subroutine? How come?
If you catch the error in func, it is already caught. Only if there's no Try..catch in func, the exception is handled in sub trysomething. -- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister. org/news/learn2quote.htm l
"James Radke" <jr*****@wi.rr. com> schrieb I was under the impression that if you use:
#1) try... catch end try
versus
#2 try catch ex as exception end try
that the error would be caught, processing halted, AND the exception passed up to the calling routine... Only if you use #2 would the exception be fully handled in the routine.. is that not correct?
Both versions are almost equal. #2 additionally supplies access to the
thrown exception. #1 doesn't. That's the only difference. In both versions
the exception is caught and not passed to the calling routine because it's
already handled.
As Herfried wrote, you can rethrow the exception:
try...
catch
'...
throw
end try
--
Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
James, that the error would be caught, processing halted, AND the exception
passed up to the calling routine...
You're thinking of
try
...
finally
end try
Because there is no catch clause in the above the Exception will be passed
to the calling routine, however the code in the finally block will be
executed. Useful to close connections without actually doing anything to the
Exception.
As Herfried & Armin pointed out, if you want the exception passed to the
calling routine you need to use Catch with Throw inside.
Hope this helps
Jay
"James Radke" <jr*****@wi.rr. com> wrote in message
news:em******** *****@TK2MSFTNG P11.phx.gbl... I was under the impression that if you use:
#1) try... catch end try
versus
#2 try catch ex as exception end try
that the error would be caught, processing halted, AND the exception
passed up to the calling routine... Only if you use #2 would the exception be fully handled in the routine.. is that not correct?
Jim
"Armin Zingler" <az*******@free net.de> wrote in message news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. "James Radke" <jr*****@wi.rr. com> schrieb [code]
if in module class clsX - func: I also have try catch block. This try catch does catch an error, however, it is never passed up to the trysomething subroutine? How come?
If you catch the error in func, it is already caught. Only if there's no Try..catch in func, the exception is handled in sub trysomething. -- Armin
http://www.plig.net/nnq/nquote.html http://www.netmeister. org/news/learn2quote.htm l
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jacek Dziedzic |
last post by:
Hi!
In my main() function I have a last-resort exception construct that
looks
like this:
int main() {
try {
// ... program code
}
|
by: Woody Splawn |
last post by:
I have a try catch statement in a fucntion that is supposed to return a true
or a false
My code looks like this:
Try
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter("Select JnlType, Description from
JnlType", mySqlConnection)
Dim Ds As New DataSet("X")
|
by: Tiraman |
last post by:
Hi ,
I am using allot the try catch in my code and the question is
if it is good ?
it will decrease my performance ?
one more question
|
by: Michael MacDonald |
last post by:
Does someone have a good site I can visit or explain the use of Try" and
Catch foe exception/error handling. What is the logic behind this
command and maybe an example would be great!!!!
Mike_Mac
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
|
by: pigeonrandle |
last post by:
Hi,
Does this bit of code represent complete overkill?!
try
{
//create a treenode
TreeNode tn = new TreeNode();
//add it to a treeview
tv.Nodes.Add(tn);
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |