hi
in java i found that when a method has a throws clause in the definition,
callers must either handle the exceptions thrown by the method they are
calling or "forward" the exception to the caller by specifying a throws
clause as well.
is there a similar machanism in c++? i want to force a developer to write
handlers for all possible exceptions a method of my class library can throw.
thanks
bruno
Jul 19 '05
12 3693
you are right, i cannot prevent everything, but i want to prevent exceptions
thrown within my code to cause serious application errors or crashes. if the
os fails (i mean really fails), then of course i cannot to too much.
if i force handling or "forwarding " of an exception, it is a way of "asking"
a developer "are you aware of that possible error case?"
when forcing exception handling i know everywhere in the code what errors
could occur so i can prepare the code for proper handling.
"Alexander Terekhov" <te******@web.d e> wrote in message
news:3F******** *******@web.de. .. "Ritz, Bruno" wrote: it is not about "to exercise some authority". ever had the idea that i
had the stability of the application in mind?
i just do not want uncaught exceptions.
How about terrorists or natural disasters? You can't really "force" someone to prevent them, I'm afraid.
http://article.gmane.org/gmane.comp....st.devel/22348 (Re: [boost::thread] locks, exceptions and assertions)
regards, alexander.
"Ritz, Bruno" <br********@gmx .ch> wrote in message
news:3f******** @news.swissonli ne.ch... why is that a useless mechanism?
"Jonathan Mcdougall" <DE************ ******@yahoo.ca > wrote in message news:at******** *************** *********@4ax.c om...in java i found that when a method has a throws clause in the
definition,callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the caller by specifying a throws clause as well.
Which is a completly useless mechanism.
is there a similar machanism in c++?
Of course not.
i want to force a developer to write handlers for all possible exceptions a method of my class library can
throw. Comments would be best.
Jonathan
IMO, the best way of doing this is enclosing _all_ your code in a try block,
followed by a catch(...) clause. This way, if the code in the catch clause
is reached, you will know for sure that you have an unhandled exception.
E.g.:
#include <iostream>
#include "whatever.h "
#define UnhandledExcept ionHandler() UnhandledExcept ionHandler(__FI LE__,
__LINE__)
void UnhandledExcept ionHandler(cons t char* c, int n)
{
std::cout << "Unhandled eexception in file " << c << " on line " << n <<
'\n';
}
in your code do this:
void function()
{
try
{
//everything
}
catch (MyException1 e)
{
//handle it
}
catch (MyException2 e)
{
//handle it
}
// and so on
catch (...)
{
UnhandledExcept ionHandler();
}
}
HTH,
S. Armondi This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: adi |
last post by:
Dear all,
This is more like a theoretical or conceptual question:
which is better, using exception or return code for
a .NET component?
I had created a COM object (using VB6), which uses return
code (not generating error/exception) so it is more
compatible with other programming language.
|
by: Noor |
last post by:
please tell the technique of centralize exception handling without try catch
blocks in c#.
|
by: Master of C++ |
last post by:
Hi,
I am an absolute newbie to Exception Handling, and I am trying to
retrofit exception handling to a LOT of C++ code that I've written
earlier. I am just looking for a bare-bones, low-tech exception
handling mechanism which will allow me to pass character information
about an error and its location from lower-level classes.
Can you please critique the following exception handling mechanism in
terms of my requirements ?
|
by: tom |
last post by:
Hi,
I am developing a WinForm application and I am looking for a guide on where
to place Exception Handling. My application is designed into three tiers
UI, Business Objects, and Data Access Layer. My questions is where should I
put exception handling:
1) Should it be put in all significant methods in all layers?
2) Should I create an exception base class that will handle the errors and
pass useful error messages to the user?
|
by: C# Learner |
last post by:
Some time ago, I remember reading a discussion about the strengths and
weaknesses of exception handling. One of the weaknesses that was put
forward was that exception handling is inefficient (in the way of CPU
usage), compared to the "normal" practise returning values.
How true is this? Will using using exception handling, in general, be
much less efficient than returning values, or less efficient at all?
Just curious...
| |
by: craig |
last post by:
I am wondering if there are some best practices for determining a strategy
for using try/catch blocks within an application.
My current thoughts are:
1. The code the initiates any high-level user tasks should always be
included in a try/catch block that actually handles any exceptions that
occur (log the exception, display a message box, etc.).
2. Low-level operations that are used to carry out the high level tasks
|
by: Mark Rae |
last post by:
Hi,
I wrote a Windows service for a client a few months ago, and the client has
now asked me to modify it so that it shuts itself down under certain
circumstances e.g. a catastrophic failure of the network, SQL Server
connectivity problems etc.
I've tried to explain that this probably isn't a very good idea nor is it
even necessary because the service has sufficient error and exception
handling code to take account of such situations...
|
by: Steve |
last post by:
Hi,
Is their any way to setup VS such that it forces programmers to handle all
exception (similar to Java).
Thanks
--
|
by: George2 |
last post by:
Hello everyone,
Such code segment is used to check whether function call or exception-
handling mechanism runs out of memory first (written by Bjarne),
void perverted()
{
try{
|
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,...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |