org.springframework.boot.web.server

Class PortInUseException

  • All Implemented Interfaces:
    java.io.Serializable


    public class PortInUseException
    extends WebServerException
    A PortInUseException is thrown when a web server fails to start due to a port already being in use.
    Since:
    2.0.0
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      PortInUseException(int port)
      Creates a new port in use exception for the given port.
      PortInUseException(int port, java.lang.Throwable cause)
      Creates a new port in use exception for the given port.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int getPort()
      Returns the port that was in use.
      static <E extends java.lang.Exception>
      void
      ifCausedBy(java.lang.Exception ex, java.lang.Class<E> causedBy, java.util.function.Consumer<E> action)
      Perform an action if the given exception was caused by a specific exception type.
      static void ifPortBindingException(java.lang.Exception ex, java.util.function.Consumer<java.net.BindException> action)
      Perform an action if the given exception was caused by a "port in use" BindException.
      static void throwIfPortBindingException(java.lang.Exception ex, java.util.function.IntSupplier port)
      Throw a PortInUseException if the given exception was caused by a "port in use" BindException.
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • PortInUseException

        public PortInUseException(int port)
        Creates a new port in use exception for the given port.
        Parameters:
        port - the port that was in use
      • PortInUseException

        public PortInUseException(int port,
                                  java.lang.Throwable cause)
        Creates a new port in use exception for the given port.
        Parameters:
        port - the port that was in use
        cause - the cause of the exception
    • Method Detail

      • getPort

        public int getPort()
        Returns the port that was in use.
        Returns:
        the port
      • throwIfPortBindingException

        public static void throwIfPortBindingException(java.lang.Exception ex,
                                                       java.util.function.IntSupplier port)
        Throw a PortInUseException if the given exception was caused by a "port in use" BindException.
        Parameters:
        ex - the source exception
        port - a suppler used to provide the port
        Since:
        2.2.7
      • ifPortBindingException

        public static void ifPortBindingException(java.lang.Exception ex,
                                                  java.util.function.Consumer<java.net.BindException> action)
        Perform an action if the given exception was caused by a "port in use" BindException.
        Parameters:
        ex - the source exception
        action - the action to perform
        Since:
        2.2.7
      • ifCausedBy

        public static <E extends java.lang.Exception> void ifCausedBy(java.lang.Exception ex,
                                                                      java.lang.Class<E> causedBy,
                                                                      java.util.function.Consumer<E> action)
        Perform an action if the given exception was caused by a specific exception type.
        Type Parameters:
        E - the cause exception type
        Parameters:
        ex - the source exception
        causedBy - the required cause type
        action - the action to perform
        Since:
        2.2.7