Uploaded image for project: 'JTalks Common'
  1. JTalks Common
  2. JTALKSCOMMON-15

Change such exceptions as DuplicateException to have Constructor accepting the wrong field instead of whole error message

    Details

      Description

      So instead of having

        /**
           * Create exception with specific message.
           *
           * @param message exception message
           */
          public DuplicateEmailException(String message) {
              super(message);
          }

      We need this style of exceptions:

          public DuplicateEmailException(String email) {
              this.email = email;
              super("Email is duplicated [" + email + "]");
          }

      If you think that user should be allowed to pass a custom error message, then such constructor should be created:

      public DuplicateEmailException(String email, String errorMessage)

        Attachments

          Structure

            Activity

            Hide
            ancient_mariner Alex Lysak added a comment - - edited

            Stas, is it enough to have existing constructor with 2 parameters or do we need to add additional constructor with one parameter?

            ... like that
            public DuplicateEmailException(String email)

            { super("Email is duplicated [" + email + "]"); }

            why do we need this field in class at all ?

            Show
            ancient_mariner Alex Lysak added a comment - - edited Stas, is it enough to have existing constructor with 2 parameters or do we need to add additional constructor with one parameter? ... like that public DuplicateEmailException(String email) { super("Email is duplicated [" + email + "]"); } why do we need this field in class at all ?
            Hide
            ctapobep Stanislav Bashkyrtsev added a comment -

            We don't need the field itself, but the it's better to have more smart implementation of exceptions (any exceptions). This is bad:

            public DuplicateEmailException(String message) {
                    super(message);
                }

            because besides we already have the problem described in the exception class, we force the users of this API to specify this info again. This is good:

            public DuplicateEmailException(String email) {
                    super("Email is duplicated [" + email + "]");
                }

            because we ask user to specify only needed information, and we're smart enough to figure out that the problem is in mail duplication (this is class particularly for handling such kind of problems).

            Show
            ctapobep Stanislav Bashkyrtsev added a comment - We don't need the field itself, but the it's better to have more smart implementation of exceptions (any exceptions). This is bad: public DuplicateEmailException( String message) { super (message); } because besides we already have the problem described in the exception class, we force the users of this API to specify this info again. This is good: public DuplicateEmailException( String email) { super ( "Email is duplicated [" + email + "]" ); } because we ask user to specify only needed information, and we're smart enough to figure out that the problem is in mail duplication (this is class particularly for handling such kind of problems).
            Hide
            ancient_mariner Alex Lysak added a comment -

            also fixed CRLF from windows encoding

            spent 2-3 hours

            Show
            ancient_mariner Alex Lysak added a comment - also fixed CRLF from windows encoding spent 2-3 hours

              People

              • Assignee:
                ancient_mariner Alex Lysak
                Reporter:
                ctapobep Stanislav Bashkyrtsev
              • Votes:
                0 Vote for this issue
                Watchers:
                Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 3h Original Estimate - 3h
                  3h
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 6h
                  6h

                    Structure Helper Panel