Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-16052

Clean up exception management

    XMLWordPrintable

    Details

    • Type: Clean up
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.4
    • Component/s: Runtime
    • Tags:
    • Upgrade notes:
      Hide

      For special cases, ExceptionUtils introduces 3 new methods:

      • ExceptionUtils.runtimeException(e)
        For code that needs to deal with legacy APIs throwing Exception. The usage pattern is:
        try { someobject.legacyMethod(); }

        catch (Exception e)

        { // stupid legacy API throws Exception throw ExceptionUtils.runtimeException(e); }
      • ExceptionUtils.unwrapInvoke(e)
        For code that calls Method.invoke and doesn't want to abort on errors, and that needs to make sure interrupts are treated correctly. The usage pattern is:
        try { meth.invoke(object, value); }

        catch (ReflectiveOperationException e)

        { Exception ee = ExceptionUtils.unwrapInvoke(e); log.error("cannot invoke", ee); }
      • ExceptionUtils.checkInterrupt(e)
        For code that really wants to swallow exceptions, usually temporarily, to allow several components to be called in all cases, even though at the end an exception is thrown or an error is logged. The usage pattern is:
        try { object.initialize(name); }

        catch (Exception e)

        { // deals with interrupt below ExceptionUtils.checkInterrupt(e); log.error("Failed init: " + name, e); }

      A number of interfaces don't have 'throws Exception' anymore, among them:

      • Component implementations (DefaultComponent), for methods: activate / deactivate / applicationStarted / registerExtension / unregisterExtension / registerContribution / unregisterContribution
      Show
      For special cases, ExceptionUtils introduces 3 new methods: ExceptionUtils.runtimeException(e) For code that needs to deal with legacy APIs throwing Exception. The usage pattern is: try { someobject.legacyMethod(); } catch (Exception e) { // stupid legacy API throws Exception throw ExceptionUtils.runtimeException(e); } ExceptionUtils.unwrapInvoke(e) For code that calls Method.invoke and doesn't want to abort on errors, and that needs to make sure interrupts are treated correctly. The usage pattern is: try { meth.invoke(object, value); } catch (ReflectiveOperationException e) { Exception ee = ExceptionUtils.unwrapInvoke(e); log.error("cannot invoke", ee); } ExceptionUtils.checkInterrupt(e) For code that really wants to swallow exceptions, usually temporarily, to allow several components to be called in all cases, even though at the end an exception is thrown or an error is logged. The usage pattern is: try { object.initialize(name); } catch (Exception e) { // deals with interrupt below ExceptionUtils.checkInterrupt(e); log.error("Failed init: " + name, e); } A number of interfaces don't have 'throws Exception' anymore, among them: Component implementations (DefaultComponent), for methods: activate / deactivate / applicationStarted / registerExtension / unregisterExtension / registerContribution / unregisterContribution

      Description

      There are many unneeded uses of throws Exception in method signatures. In addition, a lot of codes does catch Exception or catch Throwable which is very bad as it hides InterruptedException which prevents proper thread interrupt and Error which should never be caught.

      -> clean this up

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: