473,320 Members | 1,991 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,320 software developers and data experts.

abstraction level of error handling

Hi everyone, I'm reading "The C++ Programming Language" (Bjarne
Stroustrup, 3rd edition). At page 193, he said "Doing error handling
using the same level of abstraction as the code that caused the error
is hazardous; the error-handling code might repeat the same error that
triggered the error handling in the first place", and I don't
understand it clearly. So it would be very nice if someone here can
explain it more clearly. Thanks in advance.
Sep 5 '08 #1
2 1483
nguyenminhhai wrote:
Hi everyone, I'm reading "The C++ Programming Language" (Bjarne
Stroustrup, 3rd edition). At page 193, he said "Doing error handling
using the same level of abstraction as the code that caused the error
is hazardous; the error-handling code might repeat the same error that
triggered the error handling in the first place", and I don't
understand it clearly. So it would be very nice if someone here can
explain it more clearly. Thanks in advance.
An example of what I think he means: If you have a memory allocation error,
and you return an error message or throw an exception that contains the
message as type std::string, you might trigger the same error again,
because std::string needs to allocate memory.

Sep 6 '08 #2
On Sep 6, 5:42*am, nguyenminhhai <nguyenminhhai2...@gmail.comwrote:
Hi everyone, I'm reading "The C++ Programming Language" (Bjarne
Stroustrup, 3rd edition). At page 193, he said "Doing error handling
using the same level of abstraction as the code that caused the error
is hazardous; the error-handling code might repeat the same error that
triggered the error handling in the first place", and I don't
understand it clearly. So it would be very nice if someone here can
explain it more clearly. Thanks in advance.
Rolf gave a good example.

Also, say you heave two headers error.h and streaming.h. If a
function in streaming.h finds the active precision value is negative,
it might call a function in error.h, but - even if only years later
during "improvements" to error.h, it might use the whiz-bang features
in streaming.h to pretty-print the error information. And so,
potentially, round and round she goes. In this scenario, the routines
exist at the same level of abstraction, and both are calling each
other, hence the possibility of a cycle.

As a reaction to this potential, and most beneficial in projects too
large/loose to coordinate well and/or with volatile code, developers
can consider the big picture aspects of "this library is above or
below that one", and agree that the dependency will be one-way.
Though on a much bigger scale, it's similar to having a single-
translation-unit program where you don't let yourself declare
something before defining it, as you're ensuring an ever-upward flow
of dependency culminating in main().

Anyway, this approach prevents cyclic issues, but if used followed
blindly, can also make it frustrating to access needed functionality
if you find the design didn't cater for your use. Large scale
refactoring every times this happens may not be a realistic option.
But at least for low-level error handling in less managed but volatile
code, this simple separation of levels of abstractions is a sound
approach. In an academic sense, it can also be considered to be
necessary for thorough independent testing of components.

So, in the example above, the cyclic dependency can be broken by
either adding error__private_streaming.h/cc good enough to support
error.h while promising not to call back into error.h, or creating a
cut-down streaming__private_error.h/cc to support streaming.h without
using error.h. This corresponds to the choice of which to put higher
in the levels of abstraction.

Tony
Sep 6 '08 #3

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

Similar topics

30
by: Luke Wu | last post by:
Hello, >From spending some time in clc, I've come to realize that C's model of the CPU can be totally different from the atual CPU. Is it safe to say that almost nothing can be gleaned about...
6
by: Mark Broadbent | last post by:
this might sound like an obvious question but I have found that usually these two evolve at the same time. One of the biggest reasons for creating the abstraction in the first place (in my...
6
by: José Joye | last post by:
Hello, I'm currently reading the MS Developing Web applications with c# (and VB.net). In the chapter related to Error management, there is a sample about "Page-Level Error Pages" eg: In my...
2
by: rranveer | last post by:
I've been searching for ways to perform custom error handling in an asp ..net web application and have found two ways of doing it: Page Level and Application Level. What I'm curious about is,...
4
by: David Lozzi | last post by:
Howdy, I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel and Geoffrey LeBlond. Anyway, they have some instructions on how to setup application level error handling. Most...
2
by: Eric Cathell | last post by:
I am using dOOdads as my persistence layer. I have a business object Person that sits in a Project called DOMAIN I have 2 dOOdads in a project called BLL. one is _Person and is declared...
1
by: rickycornell | last post by:
Greetings All, On past projects in PHP4 I had always just written my own libraries to deal with database interaction. Somehow I was operating in the dark that there were all these database...
8
by: Ivan S | last post by:
What are your recommendations for lightweight database abstraction library (Oracle/MySQL)? I prefer OOP. :) Tnx, Ivan.
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
0
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...
0
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
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...

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.