need info on OOP error systems

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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",
if ($imported) {
if ($filterObjectName) {
$filterObjectName = ucfirst($filterObjectName);
$filterObjectName = "Filter".$filterObjectName;
$this->filterObjectName = $filterObjectName;
$this->filterObject = &
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");     

Re: need info on OOP error systems wrote:

Quoted text here. Click to load it

  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
    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.

Quoted text here. Click to load it

I am not an ANGRY man.  Remove the rage from my email to reply.

Re: need info on OOP error systems

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) {

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

Site Timeline