#188 Throws limit

release_3.2
closed
Check (274)
5
2012-10-10
2003-06-07
No

Description:
Restrict the number of exceptions a method may throw.
Default = 1.

Rationale:
Exceptions form part of a methods interface. Declaring
a method to throw too many differently rooted
exceptions makes exception handling onerous and leads
to poor programming practices such as catch
(Exception). This check forces developers to put
exceptions into a heirachy such that in the simplest
case, only one type of exception need be checked for by
a caller but allows any sub-classes to be caught
specifically if necessary.

Discussion

  • Rick Giles

    Rick Giles - 2003-07-20

    Logged In: YES
    user_id=539926

    The following configuration of 3.2 CVS check DescendantToken
    performs this check:

    <!-- Restrict the number of exceptions a method may throw,
    request 750742 -->
    <module name="DescendantToken">
    <property name="tokens" value="LITERAL_THROWS"/>
    <property name="limitedTokens" value="IDENT"/>
    <property name="maximumNumber" value="1"/>
    <property name="maximumMessage" value="Method should
    throw no more than {1} exception(s)."/>
    </module>

     
  • Oleg Sukhodolsky

    Logged In: YES
    user_id=746148

    I'm afraid suggested configuration for DecendantToken check
    will work
    only if the chacked code doen't use fully qualified names
    for excetion types.

     
  • Dale King

    Dale King - 2003-08-25

    Logged In: YES
    user_id=130378

    Such a check would also encourage the chaining of
    exceptions (which is a good thing). So instead of having
    widely varied exceptions you could return a common
    exception chained to the actual cause of the exception.

     
  • Oleg Sukhodolsky

    Logged In: YES
    user_id=746148

    Committed in CVS for 3.2 (module ThrowsCount)

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks