need info on OOP error systems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lkrubner@geocities.com

    #1

    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 internationaliz e 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 ($filterObjectN ame=false) {
    $imported = $this->controllerForA ll->import("IntfFi lter",
    "ExteriorFilter ");
    if ($imported) {
    if ($filterObjectN ame) {
    $filterObjectNa me = ucfirst($filter ObjectName);
    $filterObjectNa me = "Filter".$filte rObjectName;
    $this->filterObjectNa me = $filterObjectNa me;
    $this->filterObject = &
    $this->controllerForA ll->getObject($fil terObjectName,
    "ExteriorFetch" );
    if (is_object($thi s->filterObject )) {
    return true;
    } else {
    $this->resultsObjec t->error("In the command setFilterObject (), in
    ExteriorFilter, we expected to get an object called
    '$filterObjectN ame', but we could not find it.", "ExteriorFilter ");
    }
    } else {
    $this->resultsObjec t->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->resultsObjec t->error("In setFilterObject (), in
    ExteriorFilter, we tried to import the interface IntfFilter, but we
    were unable to.", "ExteriorFilter ");
    }
    }

  • Mark

    #2
    Re: need info on OOP error systems

    lkrubner@geocit ies.com wrote:

    [color=blue]
    >
    > 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?[/color]

    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_funct ion(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.

    [color=blue]
    >
    >
    >
    >
    >
    > function setFilterObject ($filterObjectN ame=false) {
    > $imported = $this->controllerForA ll->import("IntfFi lter",
    > "ExteriorFilter ");
    > if ($imported) {
    > if ($filterObjectN ame) {
    > $filterObjectNa me = ucfirst($filter ObjectName);
    > $filterObjectNa me = "Filter".$filte rObjectName;
    > $this->filterObjectNa me = $filterObjectNa me;
    > $this->filterObject = &
    > $this->controllerForA ll->getObject($fil terObjectName,
    > "ExteriorFetch" );
    > if (is_object($thi s->filterObject )) {
    > return true;
    > } else {
    > $this->resultsObjec t->error("In the command setFilterObject (), in
    > ExteriorFilter, we expected to get an object called
    > '$filterObjectN ame', but we could not find it.", "ExteriorFilter ");
    > }
    > } else {
    > $this->resultsObjec t->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->resultsObjec t->error("In setFilterObject (), in
    > ExteriorFilter, we tried to import the interface IntfFilter, but we
    > were unable to.", "ExteriorFilter ");
    > }
    > }[/color]

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

    Comment

    • lkrubner@geocities.com

      #3
      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) {
      test($command);
      execute($comman d);
      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'.

      Comment

      Working...