io.github.joblo2213.sma.speedwire.SpeedwireErrorHandler Maven / Gradle / Ivy
Show all versions of sma.speedwire Show documentation
package io.github.joblo2213.sma.speedwire;
import io.github.joblo2213.sma.speedwire.protocol.InvalidTelegramException;
import java.io.IOException;
import java.net.PortUnreachableException;
import java.nio.channels.IllegalBlockingModeException;
/**
*
* The callback that is run on any occurring exceptions while reading incoming packets from sma speedwire.
*
* If you want to listen for specific types of exceptions, check the type with {@code instanceof}.
*
* Likely exceptions are:
* {@link InvalidTelegramException} - if an incoming packet can't be parsed as valid speedwire telegram
* {@link IOException} – if an I/O error occurs.
* {@link PortUnreachableException} – may be thrown if the socket is connected to a currently unreachable destination.
* Note, there is no guarantee that the exception will be thrown.
* {@link IllegalBlockingModeException} – if the socket has an associated channel,
* and the channel is in non-blocking mode.
*
* Example:
*
{@code
* speedwire.onError(e -> {
* if (e instanceof IOException) {
* //io error
* // ...
* } else if (e instanceof InvalidTelegramException) {
* //packet parsing error
* // ...
* }
* });
* }
*/
public interface SpeedwireErrorHandler {
/**
* method called upon any exception while receiving or parsing data
*
* @param e exception that was thrown
*/
void onError(Exception e);
}