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");
}
} 2 1853 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.
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'. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |