Closed mheath closed 3 years ago
Thanks Mike for this issue report and a very valuable point! I moved it to the pi4j-v2 repo as it should be handled here. Maybe together with #43 .
@mheath i wholeheartedly agree, that checked exceptions should be used very very carefully. In most cases they really do not make sense, but just disturb the writing pattern and don't bring any additional value to the table.
@savageautomate what do you think?
I'm very open to changing this behavior. Now is the time to do this on V2 before any first release.
This also links to my issue about I2C earlier on the issues list. The code seems undecided on whether an I2C write failure should be handled by a return value or by an exception. As it stands no exception is thrown but the return value always indicates success. The diff is:
--- a/plugins/pi4j-plugin-pigpio/src/main/java/com/pi4j/plugin/pigpio/provider/i2c/PiGpioI2C.java
+++ b/plugins/pi4j-plugin-pigpio/src/main/java/com/pi4j/plugin/pigpio/provider/i2c/PiGpioI2C.java
@@ -151,8 +151,7 @@ public class PiGpioI2C extends I2CBase implements I2C {
@Override
public int writeRegister(int register, byte[] data, int offset, int length) throws IOException {
Objects.checkFromIndexSize(offset, length, data.length);
- piGpio.i2cWriteI2CBlockData(this.handle, register, data, offset, length);
- return length;
+ return piGpio.i2cWriteI2CBlockData(this.handle, register, data, offset, length);
}
// -------------------------------------------------------------------
Has been handled in https://github.com/Pi4J/pi4j-v2/pull/66
I'm finding it incredibly difficult to use Pi4J 2.x with lambdas because so many methods are declared to throw
Exception
.For example, I find myself often wanting to iterate over a
List
of configuration objects and then produce aList<DigitalOutput>
. So I code something like:but this can't compile because
Context.create
throwsException
. Can we introduce something like aPi4jException
that extendsRuntimeException
and forgo using checked exceptions?I know checked exceptions have been a bike shed issue for a long long time in the Java world but with the introduction of lambda syntax, using checked exceptions has for many (may I be so bold to say most?) Java projects become an anti-pattern.