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 1210
* "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.html
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*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP09.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.html
"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*************@TK2MSFTNGP11.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*******@freenet.de> wrote in message news:%2****************@TK2MSFTNGP09.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.html
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,...
|
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...
|
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: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |