473,412 Members | 4,519 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,412 software developers and data experts.

need info on OOP error systems

This is a general computer question, but I'm writing in PHP so I'll
post this to comp.lang.php.

I've been writing a content management system. I've a Singleton object
that keeps track of all errors and stores them in an array. As things
work right now, I write out each error message individually. I'm
thinking that as the code grows, this system will not continue to
scale. Right now my software consists of 1.4 megs of PHP code. I don't
know how many error messages there are, but a reasonable guess is 1800
(I've 900 functions and classes in 900 files, and I'm guessing two
error messages in each, on average). You can see an example of what I
mean below, setFilterObject is a fairly standard class method, with 3
possible error messages when things go wrong. As you can see, I've
written out each error message in English.

There are a number of problems with this. One is that at some point I'd
like to internationalize the software, which I assume means making it
easy to rewrite the error messages in other languages. Therefore, I
assume I'm making a mistake by hard-coding them as English. The other
problem is that it takes a lot of time to write out these error
messages, and the error messages constitute a growing percent of the
code.

I know that as software project grow some system is usually put in
place to regulate error messages. Can anyone point me to tutorials or
books that have good info on this?


function setFilterObject($filterObjectName=false) {
$imported = $this->controllerForAll->import("IntfFilter",
"ExteriorFilter");
if ($imported) {
if ($filterObjectName) {
$filterObjectName = ucfirst($filterObjectName);
$filterObjectName = "Filter".$filterObjectName;
$this->filterObjectName = $filterObjectName;
$this->filterObject = &
$this->controllerForAll->getObject($filterObjectName,
"ExteriorFetch");
if (is_object($this->filterObject)) {
return true;
} else {
$this->resultsObject->error("In the command setFilterObject(), in
ExteriorFilter, we expected to get an object called
'$filterObjectName', but we could not find it.", "ExteriorFilter");
}
} else {
$this->resultsObject->error("In the command setFilterObject(), in
ExteriorFilter, we expected to be told the name of a filter object we
should look for, but we were given an empty string.", "ExteriorFetch");

}
} else {
$this->resultsObject->error("In setFilterObject(), in
ExteriorFilter, we tried to import the interface IntfFilter, but we
were unable to.", "ExteriorFilter");
}
}

Jul 17 '05 #1
2 1889
lk******@geocities.com wrote:


I know that as software project grow some system is usually put in
place to regulate error messages. Can anyone point me to tutorials or
books that have good info on this?
i haven't seen such a thing yet. it's one of those great ignored topics
of comptuer science.

having done the old COM way of doing things (integer error codes + the
ability to register properly localised 'rich error info NOW WITH TEXT!')
and the fully SEH way of doing things, i'm more convinced than ever that
SEH is the way to go. The errors are meaningful, can be elegantly captured
and managed (at least in languages that properly support them (i.e. NOT
C++)), and you can still do cleanup.

Unfortuantely, for languages like PHP, where the facilities exit, but
where the implementation might not be that great or widely used, it's a bit
challenging deciding what to do.

One thing I tried for a while with reasonable success was creating a small
error class which would take an integer error code and a resource
identifier which would point to a properly localised string in some file.

I would then call functions like:
$err = call_some_function(parms, parms, parms);
if ($err === NULL)
{
// continue along my merry way
}
else
{
echo $err->get_Message();
}

or some such thing. It requires a lot more discipline, but gave me the
benefits of SEH without actually using it.




function setFilterObject($filterObjectName=false) {
$imported = $this->controllerForAll->import("IntfFilter",
"ExteriorFilter");
if ($imported) {
if ($filterObjectName) {
$filterObjectName = ucfirst($filterObjectName);
$filterObjectName = "Filter".$filterObjectName;
$this->filterObjectName = $filterObjectName;
$this->filterObject = &
$this->controllerForAll->getObject($filterObjectName,
"ExteriorFetch");
if (is_object($this->filterObject)) {
return true;
} else {
$this->resultsObject->error("In the command setFilterObject(), in
ExteriorFilter, we expected to get an object called
'$filterObjectName', but we could not find it.", "ExteriorFilter");
}
} else {
$this->resultsObject->error("In the command setFilterObject(), in
ExteriorFilter, we expected to be told the name of a filter object we
should look for, but we were given an empty string.", "ExteriorFetch");

}
} else {
$this->resultsObject->error("In setFilterObject(), in
ExteriorFilter, we tried to import the interface IntfFilter, but we
were unable to.", "ExteriorFilter");
}
}


--
I am not an ANGRY man. Remove the rage from my email to reply.
Jul 17 '05 #2
Like you, I suspect exception handling is the most efficient way to
handle errors, but would you mind saying why you feel as you do? I'm
trying to put everything into words so I can figure out what kind of
error system I want to build.

I think exception handling can be mimiced in PHP more completely than
what your example shows. I think it requires running all functions
through a function which first tests them. Like this:

function processCommand($command) {
test($command);
execute($command);
return($command);
}

You have to use processCommand as the center of your software and run
everything through it, and you have to write test() to catch
everything, including parse errors and logic errors.

I've begun using this system in my own software and in some ways it
mimics EH. What it lacks is a way for errors to 'bubble up'. The parse
error checking is nicely automatic, as each function is in its own file
which needs to be included(), and PHP's include() function fails to
include PHP files that have parse errors, and my import() function,
which handles the including, generates a good error message. But again,
I've yet to figure a way to get any of these error messages to 'bubble
up'.

Jul 17 '05 #3

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

Similar topics

9
by: Nick Forrington | last post by:
Hi, I'm making a program and have a static Console class that I'm using to output things, these get sent to the console and also to the graphics on screen (I'm using SDL). One thing I'm having a...
4
by: Shyguy | last post by:
I have a small app that I want to distribute to users of various Operating systems from 97 to XP. Does the latest edition of Developer Edition contain the runtimes for all previous versions or do...
2
by: Kiran | last post by:
Hi, Need info about Uttara Info Systems Bangalore, who train for UNIX and C. I heard it is world famous. Regards Kiran
2
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an application that doesn't quite work on my co-workers computer. I want to install the app with debug information, in my crazy mind i thought that when an exception was...
13
by: Jeff Davis | last post by:
Right now performance isn't a problem, but this question has me curious: Let's say I have a shopping cart system where there is a "products" table that contains all possible products, and an...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
21
by: nihad.nasim | last post by:
Hi there, I have a database in Access that I need on the web. The web page should connect to the database and write records for certain tables and view records for others. I want to know a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.