Use of "catch (...)" should be reduced or mitigated

Bug #1103819 reported by Paul J. Lucas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
In Progress
High
Paul J. Lucas

Bug Description

At various places in the code, the "catch" clause of a try/catch is "catch (...)". In many cases, this isn't handled as well as it ought to be. For example:

  catch ( ZorbaException const &e ) {
    // do something
  }
  catch ( ... ) {
    // do something more drastic
  }

At the very least, an additional "catch" clause should be inserted like:

  catch ( ZorbaException const &e ) {
    // do something
  }
  catch ( std::exception const &e ) {
    // do something with e.what()
  }
  catch ( ... ) {
    // do something more drastic
  }

so that at least the information contained in the "what()" message can be preserved.

Another case is in loader_fast.cpp, FastXmlLoader::loadXml() that does a "catch (...)" and returns NULL. It's not clear this is the right thing to do. Perhaps it ought to clean-up then rethrow the exception. (This case also ought to catch std::exception for the same reason given above.)

Related branches

Changed in zorba:
status: New → In Progress
Changed in zorba:
milestone: none → 2.9
Changed in zorba:
importance: Undecided → Medium
Revision history for this message
Chris Hillery (ceejatec) wrote :

Cezar, can you take a look at the FastXmlLoader issue Paul mentions?

Changed in zorba:
assignee: Paul J. Lucas (paul-lucas) → Cezar Andrei (cezar-andrei)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

Why are there two branches for this?

Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

Why not? I fixed the catches in loader_fast and loader_dtd, pushed them to a branch and discovered there was another branch. Is there any problem if there are 2 branches, looks like launchpad supports it?

Changed in zorba:
assignee: Cezar Andrei (cezar-andrei) → Paul J. Lucas (paul-lucas)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

The file loader_dtd.cpp still isn't finished. See the "TODO" comment in the file.

Changed in zorba:
assignee: Paul J. Lucas (paul-lucas) → Cezar Andrei (cezar-andrei)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

BTW: branch bug1103819-catchAll was merged into the bug-1103819 branch so now there is only one branch. Please use the bug-1103819 branch only.

Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

I've put in bug-1103819 branch two fixes. Comments?

Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

For lines like those starting at 762 in the diff, why bother to catch the exceptions if all that happens is calling ZORBA_FATAL? You simply could not catch any exception and let it propagate upwards through the call stack.

Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

Not sure what file are you talking about but if it's src/store/naive/node_items.cpp, bzr blame shows you and daniel working on those.

It's not exactly the same, "Unexpected exception" gives a little more info on the matter. I don't know the code, to say if the message can be made more useful.

Changed in zorba:
assignee: Cezar Andrei (cezar-andrei) → Paul J. Lucas (paul-lucas)
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

I mean if you go to this page:

  https://code.launchpad.net/~zorba-coders/zorba/bug-1103819/+merge/146312

and look at the "Preview Diff" you will see that each line of the diff is numbered. If you scroll down until you see "762," that's what I'm talking about.

Those lines were apparently touched by Daniel, not me.

If you don't catch the exception at all, it will "bubble up" and eventually be caught by some other code that will also print "unexpected exception," so there's no point in catching it here.

Changed in zorba:
assignee: Paul J. Lucas (paul-lucas) → Cezar Andrei (cezar-andrei)
Changed in zorba:
assignee: Cezar Andrei (cezar-andrei) → Paul J. Lucas (paul-lucas)
Chris Hillery (ceejatec)
Changed in zorba:
milestone: 2.9 → 3.0
Chris Hillery (ceejatec)
Changed in zorba:
importance: Medium → High
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.