473,750 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reporting programming error

Greetings,

Is there a consensus as to the best way to report a programming error, for
example an out of bounds index value passed to a function? There are three
approaches that I can think of:

[1] (traditional) error return value
[2] error value in object
[2] exception

Below are examples of how they might be used by functions that check their
index parameter for for out of bounds.

// [1]
er = object.process_ index(index);
assert(er == 0);

// [2]
object.process_ index(index);
assert(object.e rror == 0);

// [3]
try { object.process_ index(index); }
catch(...) { assert(false); }

Programming errors are, I assume, most likely found via asserts. If this is
the case, the cleanest approach seems to be approach [2]. This prevents
cluttering up the call with error types and limits those references to the
assert.

Thanks
Jul 22 '05 #1
4 1704
Ian Lazarus wrote:
Greetings,

Is there a consensus as to the best way to report a programming error, for
example an out of bounds index value passed to a function? There are three
approaches that I can think of:

[1] (traditional) error return value
[2] error value in object
[2] exception


I for one like exceptions in this case. If the caller of my function
can't even use it as directed, I certainly don't trust said caller to
check for an error value. I'd just as soon pass error information back
as far as necessary to find a more responsible layer of the program.
Jul 22 '05 #2
Ian Lazarus wrote:
Is there a consensus as to the best way to report a programming error?
For example an out of bounds index value passed to a function?
There are three approaches that I can think of:

[1] (traditional) error return value
[2] error value in object
[3] exception

Below are examples of how they might be used by functions
that check their index parameter for for out of bounds.

// [1]
er = object.process_ index(index);
assert(er == 0);

// [2]
object.process_ index(index);
assert(object.e rror == 0);

// [3]
try { object.process_ index(index); }
catch(...) { assert(false); }

Programming errors are, I assume, most likely found via asserts.
If this is the case, the cleanest approach seems to be approach [2].
This prevents cluttering up the call with error types
and limits those references to the assert.


#include <iostream>

class myClass {
private:
int max_index;
public:
myClass& process_index(i nt index, const char* file, int line);
myClass& process_index(i nt index);
};

myClass& myClass::proces s_index(int index,
const char* file, int line) {
if (index < 0 || max_index < index)
std::cerr << "Index out of bounds "
<< "in function myClass::proces s_index(int) "
<< "at line #" << line
<< " in file " << file << std::endl;
return process_index(i ndex);
}

#ifndef NDEBUG
#define process_index(i ndex) \
process_index(( index), __FILE__, __LINE__)
#endif//NDEBUG

Jul 22 '05 #3
"Ian Lazarus" <no****@nowhere .net> wrote
Is there a consensus as to the best way to report a programming
error, for example an out of bounds index value passed to a
function?
There's definitely no consensus on the best way, but there is consensus on
various wrong ways.
There are three approaches that I can think of:

[1] (traditional) error return value
[2] error value in object
[2] exception

Below are examples of how they might be used by functions that check their
index parameter for for out of bounds.

// [1]
er = object.process_ index(index);
assert(er == 0);
This is the old-style C way of handling errors. The advantages are that it's
simple and it allows a programmer to ignore the error. The disadvantage is that
it allows the programmer to ignore the error.
// [2]
object.process_ index(index);
assert(object.e rror == 0);
Except under rare conditions, this is an all-around bad approach. The exception
applies to those objects whose internal state actually does change due to an
error, such as streams, sockets, files, etc. and where the object can no longer
be used until the condition is rectified. In practically all other cases, it's a
design error that associates the exit state of the operation with the static
state of the object. The only place one should be interested in the last error is
where the error occurred. Let's not even get into the mess that this approach can
cause in multi-threaded programs.
// [3]
try { object.process_ index(index); }
catch(...) { assert(false); }
This is the "standard" C++ way of handling errors. However, it has one major
disadvantage: the caller can't ignore the error. Of course, the advantage is that
the caller can't ignore the error. :-)
Programming errors are, I assume, most likely found via asserts.
The case for 'assert' is fuzzier. Many people object to asserts on a variety of
grounds, the most often voiced being that the non-debug code will be different
from the debug version and any inadvertent side-effects introduced in the asserts
will be missing from the non-debug code. Others feel that better error-handling
(standardized logging, etc.) should be used instead. Personally, I like liberally
sprinkling asserts in my code, but you shouldn't assume that it's a universal
sentiment.
If this is the case, the cleanest approach seems to be approach [2].
This prevents cluttering up the call with error types and limits those
references to the assert.


while (true) {
std::cerr << "NO!!!" << std::endl;
}

[1] and [3] are acceptable (for the record, I prefer [3]). [2] is simply
unacceptable unless the error really is part of the object's natural state.

Claudio Puviani
Jul 22 '05 #4
> Programming errors are, I assume, most likely found via asserts. If this is
the case, the cleanest approach seems to be approach [2]. This prevents
cluttering up the call with error types and limits those references to the
assert.


If your software is interactive and it's difficult to run it
twice with the same input (word processor, gui, ...), or if
program execution should never stop (monitoring system,
....), I think that the programmer should assume that there
are bugs, i.e. not rely on assert, handle errors in a clean
way (I don't like to loose data because the application
crashed due to an internal error) and output as much
information as possible to enable debugging without running
the program again because you might be unable to reproduce
the problem. The program should behave as if that particular
feature where the bug happened is missing.
Jul 22 '05 #5

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

Similar topics

4
3916
by: Fabian von Romberg | last post by:
Hi, I have installed Sql Reporting Services on 2 machines, one is WIN 2000 PRO and the other one is WIN 2000 ADV. SERVER. When I try to access a report using the webbrowser, I get the following error, this happens only if try access the report on the SERVER, it I try on my local machine, it works just fine. Any help will be much appreciated. Thanks in advance, Fabian von Romberg
0
1176
by: kt | last post by:
We want to automatically turn off the error reporting options using Windows API functions for the following functions area Click on Start, Settings, Control Panel, System, the Advanced tab and Error Reporting (at the bottom of the screen), which launches the Error Reporting screen. Another way to get to that screen: Open My Computer, right-click on Properties, click on Advanced tab and Error Reporting. Any assistance would be welcome.
0
2648
by: Joshua V. | last post by:
We are trying to implement Windows Error Reporting from within our VB.Net application. Basically we want to replace the standard unhandled exception message we use with the Windows Error Reporting message. This will provide our users the ability to send the crash report to Microsoft, which in turn will allow us to get it. We did a search for Visual Studio help to see what that might turn up and came across the “ReportFault”...
5
692
by: Paul Furman | last post by:
What is the proper way to turn off error reporting? I'm on a shared server so... "Note: Although display_errors may be set at runtime (with ini_set ()), it won't have any affect if the script has fatal errors. This is because the desired runtime action does not get executed." .... has me confused if this will really work. Sorry I'm rusty on this. "To set at runtime, use the error_reporting(). See also the
1
6479
by: rmk | last post by:
How can I get the 2000 and 2005 versions of SQL Server Reporting Services both working on my development laptop ????? I have ASP.NET 1.1 and 2.0 installed on my laptop. I have Visual Studio 2003 and 2005 installed on my laptop. I have my default website configured for ASP.NET 2.0. I have the developer edition of SQL Server 2000 installed on my laptop as
1
1378
by: Melissa Nava | last post by:
Have an online system. Currently the error reporting either does: A) logs to a file, B) databases errors or C) emails individual errors. Also have phone notifications for systematically calling the programmer on-call. There are pros and cons of each, of course... I'm curious as to what others do for their error reporting. Mind you this is a 24/7 application, and if something happens I have to
3
1991
by: =?Utf-8?B?QS4gUm9iaW5zb24=?= | last post by:
I have been looking high and low and can't seem to find anything a little more detailed on the whole RS utility. What I'm looking for specifically is some type of programming reference. Also, I created a new VB project in VS2005, but yet when I write any code, Intellisense doesn't pick up anything. What reference/class do I need to add to the projuect? I've been looking through the available references under PROJECT>ADD REFERENCE and...
8
5020
by: Paul Furman | last post by:
How do I turn off MySQL error reporting? I set error_reporting(0); but that doesn't seem to be working.
0
2241
by: fperri | last post by:
Hi, I am trying to configure reporting services which I just added to an already existing installation of SQL Server 2005. When I am in the reporting services configuration manager and I am trying to create the reporting services database I get the following error: Verifying Database Edition The feature: "Using other editions of SQL Server for report data sources and/or the report server database" is not supported in this edition of...
0
8999
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9394
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...
1
9338
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,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
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 projectplanning, coding, testing, and deploymentwithout 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...
0
4712
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...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.