Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8282688

Add constructors taking a cause to SocketException

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • source
    • minimal
    • Add conventional constructors taking a cause to an exception class.
    • Java API
    • SE

      Summary

      Add conventional constructors that take a cause to SocketException to avoid the need to call initCause as part of creating the exception.

      Problem

      The creation of many SocketExceptions involves setting the cause, but the set of constructors does not include any ones taking a cause.

      Solution

      Add the two missing conventional constructors that take a cause argument.

      Specification

      --- a/src/java.base/share/classes/java/net/SocketException.java
      +++ b/src/java.base/share/classes/java/net/SocketException.java
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -52,4 +52,27 @@ public class SocketException extends IOException {
            */
           public SocketException() {
           }
      +
      +    /**
      +     * Constructs a new {@code SocketException} with the
      +     * specified detail message and cause.
      +     *
      +     * @param msg the detail message.
      +     * @param cause the cause
      +     * @since 19
      +     */
      +    public SocketException(String msg, Throwable cause) {
      +        super(msg, cause);
      +    }
      +
      +    /**
      +     * Constructs a new {@code SocketException} with the
      +     * specified cause.
      +     *
      +     * @param cause the cause
      +     * @since 19
      +     */
      +    public SocketException(Throwable cause) {
      +        super(cause);
      +    }
       }

            darcy Joe Darcy
            darcy Joe Darcy
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: