473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Try..Catch through sub/functions

HI everyone,

I have a sub that executes a query, within the sub there is a try,
catch, finally block. lets call this subA.

I also have another sub (subB) that calls SubA, and another Sub (SubC)
that calls SubB.

SubC (with Try..Catch) SubB (without Try..Catch) SubA (with
Try..Catch)

SubC has a try..catch block and so does SubA. If SubA does encounter
an error, why does it not error up through the subs?? SubB does NOT
have a try..catch block

So i have to turn these subs into functions and return a 1 or 0,
depending on whether a error has occurred or not??

Sorry if this is a silly stupid question, i am still getting to grips
with .net 2.0

Aug 22 '06 #1
4 1588
A catch statement does just that. It catches an exception, preventing the
exception from stopping execution. So, if you have a method that calls
another method, and the second method has a try/catch block in it, if an
exception occurs in the second method, it does not get thrown, but caught.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Nemisis" <da*********@hotmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
HI everyone,

I have a sub that executes a query, within the sub there is a try,
catch, finally block. lets call this subA.

I also have another sub (subB) that calls SubA, and another Sub (SubC)
that calls SubB.

SubC (with Try..Catch) SubB (without Try..Catch) SubA (with
Try..Catch)

SubC has a try..catch block and so does SubA. If SubA does encounter
an error, why does it not error up through the subs?? SubB does NOT
have a try..catch block

So i have to turn these subs into functions and return a 1 or 0,
depending on whether a error has occurred or not??

Sorry if this is a silly stupid question, i am still getting to grips
with .net 2.0

Aug 22 '06 #2
Bascially an exception "bubbles" up by design (i.e. will be handled by the
nearest try/catch). If you catch it at a lower level you prevent bubbling.
In some cases you could rethrow the exception (if you want to perform
something where it fails but still have outer procedures do something in
case of a failure).

--
Patrice

"Nemisis" <da*********@hotmail.coma écrit dans le message de news:
11**********************@i42g2000cwa.googlegroups. com...
HI everyone,

I have a sub that executes a query, within the sub there is a try,
catch, finally block. lets call this subA.

I also have another sub (subB) that calls SubA, and another Sub (SubC)
that calls SubB.

SubC (with Try..Catch) SubB (without Try..Catch) SubA (with
Try..Catch)

SubC has a try..catch block and so does SubA. If SubA does encounter
an error, why does it not error up through the subs?? SubB does NOT
have a try..catch block

So i have to turn these subs into functions and return a 1 or 0,
depending on whether a error has occurred or not??

Sorry if this is a silly stupid question, i am still getting to grips
with .net 2.0

Aug 22 '06 #3
Hi,

Patrice wrote:
Bascially an exception "bubbles" up by design (i.e. will be handled by the
nearest try/catch). If you catch it at a lower level you prevent bubbling.
In some cases you could rethrow the exception (if you want to perform
something where it fails but still have outer procedures do something in
case of a failure).
The main difference between standard "bubble" models and the exception
model is that in the standard "bubble" model, the bubbles are propagated
without the user having to do it explicitly. In the opposite, the user
has to specifiy if he wants to stop the bubbling. For exceptions,
however, the "catch" statement stops the exception from going further,
unless the user explicitly throws it again for the next level.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Aug 22 '06 #4
Thank you all for your replies, i figured it out afterwards. It was
because i wasnt rethrowing an exception after the child try..catch
caught the exemption.

This way is bubbles up to the parent sub/function, as you all said.

Thanks again everyone

Aug 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
4
by: nrhayyal | last post by:
hi all, i am facing a problem in catching an exception which is uncaught in any of the catch block. not doing so will gives me coredump. I tried by rewriting set_unexpected() and set_terminate()...
5
by: Steve Murphy | last post by:
I have a couple of standard Try/Catch blocks that I use repeatedly. Is there anyway to wrap these blocks into a method call? Or does C# have anything like a C++ macro? Thanks, Steve Murphy
18
by: Simon | last post by:
I was of the impression that code placed after a Try...Catch block was only executed if there was no exception thrown. I've got some VB.net code as part of a Windows form that executes even...
4
by: chris | last post by:
Hi, I write some code guarded with exception handling... simplified code look like this... int main(int argc, char* argv){ try{
13
by: Bit byte | last post by:
Is there any way of retrievieng error information (say, from a 'global' or system wide) error object - when you are in a catch all statement block? Sometimes it cannot be helped, when something...
2
by: robert | last post by:
When employing complex UI libs (wx, win32ui, ..) and other extension libs, nice "only Python stack traces" remain a myth. Currently I'm hunting again a rare C-level crash bug of a Python based...
5
by: stevewilliams2004 | last post by:
I was wondering if someone could explain the output I am getting for the program below. What I expected from the main program output was "Cat" but instead I see "Mammal". The output is also...
3
by: Martin | last post by:
Hi. I need to identify the type of the exception in the universal handler (catch (...)) for debugging purposes. Point is that I write a testing console application, which must call some...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.