Skip to content

Make JSSC exceptions extend IOException instead of Exception #160

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/main/java/jssc/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ public class SerialPort {
* Construct a serial port object with the specified <code>portName</code>
*
* @param portName Name of the port, e.g. <code>COM1</code>, <code>/dev/tty.FOO</code>, etc.
* @throws NullPointerException if <code>portName</code> is null.
*/
public SerialPort(String portName) {
if (portName == null) {
throw new NullPointerException();
}
this.portName = portName;
serialInterface = new SerialNativeInterface();
}
Expand Down Expand Up @@ -205,14 +209,9 @@ public synchronized boolean openPort() throws SerialPortException {
if(portOpened){
throw new SerialPortException(this, "openPort()", SerialPortException.TYPE_PORT_ALREADY_OPENED);
}
if(portName != null){
boolean useTIOCEXCL = (System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL) == null &&
System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL.toLowerCase()) == null);
portHandle = serialInterface.openPort(portName, useTIOCEXCL);//since 2.3.0 -> (if JSSC_NO_TIOCEXCL defined, exclusive lock for serial port will be disabled)
}
else {
throw new SerialPortException(this, "openPort()", SerialPortException.TYPE_NULL_NOT_PERMITTED);//since 2.1.0 -> NULL port name fix
}
boolean useTIOCEXCL = (System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL) == null &&
System.getProperty(SerialNativeInterface.PROPERTY_JSSC_NO_TIOCEXCL.toLowerCase()) == null);
portHandle = serialInterface.openPort(portName, useTIOCEXCL);//since 2.3.0 -> (if JSSC_NO_TIOCEXCL defined, exclusive lock for serial port will be disabled)
if(portHandle == SerialNativeInterface.ERR_PORT_BUSY){
throw new SerialPortException(this, "openPort()", SerialPortException.TYPE_PORT_BUSY);
}
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/jssc/SerialPortException.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
*/
package jssc;

import java.io.IOException;

/**
*
* @author scream3r
*/
public class SerialPortException extends Exception {
public class SerialPortException extends IOException {
final private static long serialVersionUID = 1L;
/** Port already opened **/
final public static String TYPE_PORT_ALREADY_OPENED = "Port already opened";
Expand All @@ -42,14 +44,6 @@ public class SerialPortException extends Exception {
final public static String TYPE_LISTENER_THREAD_INTERRUPTED = "Event listener thread interrupted";
/** Can't remove event listener **/
final public static String TYPE_CANT_REMOVE_LISTENER = "Can't remove event listener, because listener not added";
/**
* @since 0.8
*/
final public static String TYPE_PARAMETER_IS_NOT_CORRECT = "Parameter is not correct";
/**
* @since 0.8
*/
final public static String TYPE_NULL_NOT_PERMITTED = "Null not permitted";
/**
* @since 0.9.0
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jssc/SerialPortTimeoutException.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
*/
package jssc;

import java.io.IOException;

/**
*
* @author scream3r
*/
public class SerialPortTimeoutException extends Exception {
public class SerialPortTimeoutException extends IOException {
final private static long serialVersionUID = 1L;

/** Serial port object **/
Expand Down