Hi all,
I'm working on a small embedded system (think microcontroller with uC/OS-II)
and I'm considering which convention to use for error handling in our
internal "API". Since I'm using two existing APIs (a low-level HAL and the
OS API) I already have mixed conventions since some return 0 for failure,
some return 0 for "no-error", etc.
I'm leaning toward the following basic rules, please critique at will:
1) Functions return what's convenient instead of forcing into a common
return-code convention. I don't like to have to write two lines of code
instead of one when testing return codes.
a) Boolean functions return 1/0, therefore boolean functions are not allowed
to fail
b) I/O functions return number of bytes read/written. Return of zero
indicates end-of-file, negative return indicates error
c) Functions that can fail and return a value that can be positive, negative
or zero have to return the error via pointer-to-argument. That allows
putting the function call into an if-statement when looking for a specific
return value
2) Keep a global header file with a list of error codes (a la winerror.h).
OS and HAL error codes get mapped to our global error codes as needed.
a) all error codes are negative
b) error codes are scalar (no bitfields), multiple concurrent error codes
have to be resolved by a separate mechanism
3) Have a global error code that can be returned via global function (a la
GetLastError()) .
a) successful completion of a function (generally) does not overwrite last
error
b) last error is kept per thread
Comments? Suggestions?
Thanks,
Andrew 2 1605
"andrew queisser" <andrew.queisse r at hp com> wrote I'm working on a small embedded system (think microcontroller with uC/OS-II) and I'm considering which convention to use for error handling in our internal "API". Since I'm using two existing APIs (a low-level HAL and the OS API) I already have mixed conventions since some return 0 for failure, some return 0 for "no-error", etc.
Comments? Suggestions?
There is no easy solution tot he problem of errors.
You need one type when debugging, another type when distributing beta type
code to users, and a third type when you know the code itself is robust but
input may not be.
Sometimes you want code to be reusable, and sometimes you wnat a centralised
list of error codes. You can't have both.
One mistake the designer of the standard libary made was not to have any way
of querying the line number of an input file from its file pointer.
That would be one recommendation if you are doing IO from scratch,
preseuming your input is text which could potentially be corrupted.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $6.90 paper, available www.lulu.com
In article <dt**********@n wrdmz03.dmz.ncs .ea.ibs-infra.bt.com>,
Malcolm <re*******@btin ternet.com> wrote: One mistake the designer of the standard libary made was not to have any way of querying the line number of an input file from its file pointer. That would be one recommendation if you are doing IO from scratch, preseuming your input is text which could potentially be corrupted.
hmmm, the number of times I've needed the input line number in a C program
is... ummm, small enough that I'm having a hard time recalling any
instances.
I've needed the input line number a number of times in perl, awk, ed and
sed, but very rarely in C.
What kind of programs do you find that this feature would be
a noticable advantage in? Is it mostly a matter of wanting reusable
code that doesn't have to know how the rest of the program is
keeping track of the line numbers ?
--
Programming is what happens while you're busy making other plans. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Don Vaillancourt |
last post by:
Hello all,
Over the years as I design more database schemas the more I come up with
patterns in database design. The more patterns I recognize the more I
want to try to design some kind of generic design patterns that can be
used and shared amongst many sub-schemas.
For example, the grouping of entities. I may have the following tables:
employee, product and client. These tables have no direct relationship
with each other. But...
|
by: sk |
last post by:
I have an applicaton in which I collect data for different parameters
for a set of devices. The data are entered into a single table, each
set of name, value pairs time-stamped and associated with a device.
The definition of the table is as follows:
CREATE TABLE devicedata
(
device_id int NOT NULL REFERENCES devices(id), -- id in the device
|
by: Test User |
last post by:
Hi all, (please excuse the crosspost as I'm trying to reach as many people
as possible)
I am somewhat familiar with Access 2000, but my latest project has me
stumped. So, I defer to you experts.
I've been asked to create a Daily Log sheet to be distributed to some of our
clerks.
For each day, the clerk is to log tasks worked on for the day, (i.e worked
on the johnson account).
|
by: rodchar |
last post by:
Hey all,
I'm trying to understand Master/Detail concepts in VB.NET. If I do a data
adapter fill for both customer and orders from Northwind where should that
dataset live?
What client is responsible for instantiating the orders class? Would it be
the ui layer or the master class in the business layer?
thanks,
|
by: tshad |
last post by:
Many (if not most) have said that code-behind is best if working in teams -
which does seem logical.
How do you deal with the flow of the work?
I have someone who is good at designing, but know nothing about ASP. He can
build the design of the pages in HTML with tables, labels, textboxes etc.
But then I would need to change them to ASP.net objects and write the code
to make the page work (normally I do this as I go - can't do this...
| |
by: roN |
last post by:
Hi,
I'm creating a Website with divs and i do have some troubles, to make it
looking the same way in Firefox and IE (tested with IE7). I checked it with
the e3c validator and it says: "
This Page Is Valid XHTML 1.0 Transitional!" but it still wouldn't look the
same.
It is on http://www.dvdnowkiosks.com/new/theproduct.php scroll down and
recognize the black bottom bar when you go ewith firefox(2.0) which isn't
there with IE7. Why does...
|
by: JoeC |
last post by:
I have a question about designing objects and programming. What is the
best way to design objects? Create objects debug them and later if you
need some new features just use inhereitance. Often times when I
program, I will create objects for a specific purpose for a program and
if I need to add to it I just add the code.
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the end of this message, but I
will start with an overview of the problem.
I've made a content management solution for my work with a decently
structured relational database system. The CMS stores articles. The CMS also
stores related items --...
|
by: neelsmail |
last post by:
Hi,
I have been working on C++ for some time now, and I think I have a
flair for design (which just might be only my imagination over-
stretched.. :) ). So, I tried to find a design certification, possibly
that involves C++, but, if not, C++ and UML. All I could find was Java
+ UML design certifications (one such is detailed on
http://www.objectsbydesign.com/tools/certification.html). Although UML
is expected to be language independent,...
|
by: indrawati.yahya |
last post by:
In a recent job interview, the interviewer asked me how I'd design
classes for the following problem: let's consider a hypothetical
firewall, which filters network packets by either IP address, port
number, or both. How should we design the classes to represent these
filters?
My answer was:
class FilterRule
{
|
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...
| |
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: 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...
|
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: 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();...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |