org.springframework.boot.web.server

Class PortInUseException

  • All Implemented Interfaces:
    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
    Author:
    Andy Wilkinson, Phillip Webb
    See Also:
    Serialized Form
    • 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,
                                  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(Exception ex,
                                                       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(Exception ex,
                                                  Consumer<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 Exception> void ifCausedBy(Exception ex,
                                                            Class<E> causedBy,
                                                            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

Copyright © 2021 Pivotal Software, Inc.. All rights reserved.