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

Report writeBytes errors via java exceptions #146

Conversation

hiddenalpha
Copy link

No description provided.

@tresf
Copy link

tresf commented Nov 8, 2023

We can avoid changing the method signatures by wrapping the IOException. This will maintain the existing method signatures while providing consistent exception messages to the client.

    /** Exception occurred in native code **/
    final public static String TYPE_NATIVE_EXCEPTION = "Native exception occurred: %s";
    // ...
    public static SerialPortException wrapNativeException(Exception e, SerialPort port, String methodName) {
        return new SerialPortException(port, methodName, String.format(TYPE_NATIVE_EXCEPTION, e.getLocalizedMessage()));
    }
    public boolean writeBytes(byte[] buffer) throws SerialPortException {
        checkPortOpened("writeBytes()");
        boolean success;
        try {
            success = serialInterface.writeBytes(portHandle, buffer);
        } catch(IOException io) {
            throw SerialPortException.wrapNativeException(io, this, "writeBytes");
        }
        return success;
    }

@tresf tresf self-requested a review November 8, 2023 18:32
Copy link

@tresf tresf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested per #146 (comment)

@hiddenalpha hiddenalpha requested a review from tresf November 8, 2023 19:40
@tresf tresf merged commit 4a8e4ac into java-native:master Nov 8, 2023
@hiddenalpha hiddenalpha deleted the report-write-bytes-errors-as-exceptions-20231108 branch November 9, 2023 01:05
@pietrygamat pietrygamat added this to the 2.9.6 milestone Dec 1, 2023
@hiddenalpha hiddenalpha restored the report-write-bytes-errors-as-exceptions-20231108 branch February 16, 2024 20:53
@hiddenalpha hiddenalpha deleted the report-write-bytes-errors-as-exceptions-20231108 branch November 23, 2024 18:46
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

Successfully merging this pull request may close these issues.

3 participants