Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 447 forks source link

Updating from 1.0 to 1.2 breaks #474

Closed SElab2019 closed 3 years ago

SElab2019 commented 4 years ago

When I try to upgrade pi4j-core from 1.0 to version 1.2. The following code breaks.

public class BusFactory {

    public I2CBus createBus() throws IOException, InterruptedException {
        int busId;
        String type = SystemInfo.getBoardType().name();

        if (type.indexOf("ModelA") > 0) {
            busId = I2CBus.BUS_0;
        } else {
            busId = I2CBus.BUS_1;
        }

        return I2CFactory.getInstance(busId);
    }

}

The code should pass, but it throws an error:

unreported exception com.pi4j.io.i2c.I2CFactory.UnsupportedBusNumberException; must be caught or declared to be thrown
savageautomate commented 3 years ago

Closed. This was a minor API change where UnsupportedBusNumberException was added to I2CFactory.getInstance(). Implementing code must handle this exception.

UnsupportedBusNumberException perhaps should have been implemented as extending a RuntimeException, but its been there since v1.1 and we probably should not modify the public interface signature at this point.