Class PortInUseException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.boot.web.server.WebServerException
org.springframework.boot.web.server.PortInUseException
- All Implemented Interfaces:
Serializable
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:
-
Constructor Summary
ConstructorsConstructorDescriptionPortInUseException(int port) Creates a new port in use exception for the givenport.PortInUseException(int port, Throwable cause) Creates a new port in use exception for the givenport. -
Method Summary
Modifier and TypeMethodDescriptionintgetPort()Returns the port that was in use.static <E extends Exception>
voidifCausedBy(Exception ex, Class<E> causedBy, Consumer<E> action) Perform an action if the given exception was caused by a specific exception type.static voidifPortBindingException(Exception ex, Consumer<BindException> action) Perform an action if the given exception was caused by a "port in use"BindException.static voidthrowIfPortBindingException(Exception ex, IntSupplier port) Throw aPortInUseExceptionif 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
-
Constructor Details
-
PortInUseException
public PortInUseException(int port) Creates a new port in use exception for the givenport.- Parameters:
port- the port that was in use
-
PortInUseException
Creates a new port in use exception for the givenport.- Parameters:
port- the port that was in usecause- the cause of the exception
-
-
Method Details
-
getPort
public int getPort()Returns the port that was in use.- Returns:
- the port
-
throwIfPortBindingException
Throw aPortInUseExceptionif the given exception was caused by a "port in use"BindException.- Parameters:
ex- the source exceptionport- a suppler used to provide the port- Since:
- 2.2.7
-
ifPortBindingException
Perform an action if the given exception was caused by a "port in use"BindException.- Parameters:
ex- the source exceptionaction- 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 exceptioncausedBy- the required cause typeaction- the action to perform- Since:
- 2.2.7
-