473,800 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

should we call exit() inside exceptional catching blocks

Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?

try {
cnn = env->createConnecti on(user, pwd, db);
} catch (SQLException &esql){
cerr << "DB Exception: " << esql.getMessage ();
/* line x ? */
} catch (exception &e){
cerr << "Exception: " << e.what();
/* line x + 3 ? */
}

/*more code*/

Mar 26 '07 #1
4 1810
On 26 Mrz., 11:23, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?

try {
cnn = env->createConnecti on(user, pwd, db);} catch (SQLException &esql){

cerr << "DB Exception: " << esql.getMessage ();
/* line x ? */} catch (exception &e){

cerr << "Exception: " << e.what();
/* line x + 3 ? */

}

/*more code*/
If it's a critical exception that stops the execution of your
application, why do you catch it here? You should have a try/catch
statement in your lowest application level (your main function for
example) that catches all uncaught exceptions. This allows all
destructors in the stack to be called and makes it possible to
gracefully clean up everything.

--
Alexander Block

Mar 26 '07 #2
On Mar 26, 1:28 am, "Alexander Block" <abloc...@googl email.comwrote:
On 26 Mrz., 11:23, "lovecreatesbea ...@gmail.com"

<lovecreatesbea ...@gmail.comwr ote:
Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?
try {
cnn = env->createConnecti on(user, pwd, db);} catch (SQLException &esql){
cerr << "DB Exception: " << esql.getMessage ();
/* line x ? */} catch (exception &e){
cerr << "Exception: " << e.what();
/* line x + 3 ? */
}
/*more code*/

, why do you catch it here? You should have a try/catch
Do you mean the second try/catch block in my previous post?

//...
} catch (exception &e){
//...
statement in your lowest application level (your main function for
example) that catches all uncaught exceptions. This allows all
destructors in the stack to be called and makes it possible to
gracefully clean up everything.
Mar 26 '07 #3
On 26 Mrz., 16:43, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
On Mar 26, 1:28 am, "Alexander Block" <abloc...@googl email.comwrote:
On 26 Mrz., 11:23, "lovecreatesbea ...@gmail.com"
<lovecreatesbea ...@gmail.comwr ote:
Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?
try {
cnn = env->createConnecti on(user, pwd, db);} catch (SQLException &esql){
cerr << "DB Exception: " << esql.getMessage ();
/* line x ? */} catch (exception &e){
cerr << "Exception: " << e.what();
/* line x + 3 ? */
}
/*more code*/
, why do you catch it here? You should have a try/catch

Do you mean the second try/catch block in my previous post?

//...} catch (exception &e){

//...
statement in your lowest application level (your main function for
example) that catches all uncaught exceptions. This allows all
destructors in the stack to be called and makes it possible to
gracefully clean up everything.
I mean both. Having a rethrowing exception handler makes only sense if
you need to do special clean up (deallocating buffers for example).

Using exit() results in an abrupt exit. No destructors will be called
after that.

Mar 26 '07 #4
On 3ÔÂ26ÈÕ, ÏÂÎç5ʱ28·Ö, "Alexander Block" <abloc....@goog lemail.comwrote :
On 26 Mrz., 11:23, "lovecreatesbea ...@gmail.com"

<lovecreatesbea ...@gmail.comwr ote:
Is the following code (without any code at lines x and x + 3) correct?
Is it better to call exit() or re-throw the exceptions at line x and
line x + 3?. What is the better code should we place at line x and
line x + 3?
try {
cnn = env->createConnecti on(user, pwd, db);} catch (SQLException &esql){
cerr << "DB Exception: " << esql.getMessage ();
/* line x ? */} catch (exception &e){
cerr << "Exception: " << e.what();
/* line x + 3 ? */
}
/*more code*/

If it's a critical exception that stops the execution of your
application,
why do you catch it here? You should have a try/catch
statement in your lowest application level (your main function for
example)
Thank you. Please correct me if I misunderstand the knowledge.

Placing exception handling code in the main() function and without
placeing them in other called functions makes the code more cleaner
and simpler.
... that catches all uncaught exceptions.
But still place some special exception handling code for special non-
main() function? Doesn't this conflicts with the rule above?
This allows all
destructors in the stack to be called and makes it possible to
gracefully clean up everything.
Does this relate to object scope things?

Mar 27 '07 #5

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

Similar topics

40
3051
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the goodness of Python whenever I talk with fellow developers, but I always hit a snag when it comes to discussing the finer points of the execution model (specifically, exceptions). Without fail, when I start talking with some of the "old-timers"...
5
10941
by: Blatwurst | last post by:
I'm trying to implement a simple server in C#. I want to do the classic thing of spinning off a thread that just blocks in a Socket.Accept() call until a request comes in. At that point, the Accept() returns, the thread spins off another thread to handle the request, and then calls Accept() again. This all works fine except that I can find no way to kill the thread that is blocked in the Accept() call when I want to shut down the server. ...
58
4700
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split (PHONE_LIST, "_+")) { Console.WriteLine (phoneNumber); } } Output: 495.1000
32
5893
by: Protoman | last post by:
I have a function that calculates the mean of the some numbers; I need it to accept any number of parameters (one needs to be the number of the other parameters) Can you help me out here? Here's the function: const long double& mean(long long x) { vector<int> v(x); for(int i= 1; i <=x; ++i) { v.push_back(i);
4
1813
by: prashantkumar1982 | last post by:
I am using the select call to read from many sockets. I don't want to call read on every socket to check if it is closed, as it defeats the purpose of using the select call. Is there any way to know whether one of the sockets have been closed, without actually testing each socket.
2
2238
by: Greg Merideth | last post by:
This little bugger of a problem took us most of the day to track down but I'm glad it happened as I would like to know why the WSDL generated code that operates inside of a try..catch block throws an exception to the screen when it craps out instead of being caught by the try..catch block. Basically, from inside of VS 2003 I added the reference to the web service using a shared .dll to pass a class reference between the client/server. ...
20
3980
by: Cybertof | last post by:
Hello, Is there a good way to call a big time-consumming function from an ActiveX DLL (interoped) through a thread without blocking the main UI ? Here are the details : I have a class CInteropCall encapsulating a call to a visual basic ActiveX DLL function named FillAlloc_ArrayStruct_Double(), which is allocating a big struct array an fills it using a inner loop
21
2703
by: Jim Langston | last post by:
I'm sure this has been asked a few times, but I'm still not sure. I want to create a function to simplify getting a reference to a CMap in a map. This is what I do now in code: std::map<unsigned int, CMap*>::iterator ThisMapIt = World.Maps.find( ThisPlayer.Character.Map ); if ( ThisMapIt != World.Maps.end() )
13
3943
by: lister | last post by:
If I want to move something to a new line, should I be using <br/>, or is there a way of doing it in CSS? I was just thinking if it was possible in CSS then it would be better as otherwise the layout is part of the markup. Cheers, Lister
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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, 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...
0
10275
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 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...
0
9085
agi2029
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...
1
7576
isladogs
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...
0
6811
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();...
0
5471
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...
3
2945
bsmnconsultancy
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...

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.