Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is an IllegalStateException thrown instead of an IOException #133

Open
retrodaredevil opened this issue May 23, 2020 · 0 comments
Open

Comments

@retrodaredevil
Copy link

retrodaredevil commented May 23, 2020

I was using this library and for some reason my serial port disconnected, (not the fault of this library). That caused this:

PureJavaSerialPort.this.close();

line to be ran and an IOException was thrown. My program caught the IOException and tried to continue normally. However, the next time my program tried to write, since the serial port was closed, m_FD was -1, so the write called checkState and this line ran:
failWithIllegalStateException();

In my opinion, throwing an IllegalStateException (PureJavaIllegalStateException) makes no sense, especially since I'm in the middle of a write and an IOException should really be thrown instead. From the javadoc documentation of write: "IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed"

I think this should be changed to an IOException to be consistent with other OutputStreams. My guess is that there are probably a few other places where an IOException makes more sense than a PureJavaIllegalArgumentException, but I'd like to hear thoughts on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant