Skip to content

Commit 0b59de3

Browse files
committed
Using LibUsbException instead of RuntimeException
1 parent cb15af2 commit 0b59de3

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/main/java/org/usb4java/examples/DumpDevices.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.usb4java.DeviceHandle;
1414
import org.usb4java.DeviceList;
1515
import org.usb4java.LibUsb;
16+
import org.usb4java.LibUsbException;
1617

1718
/**
1819
* Dumps the descriptors of all available devices.
@@ -43,8 +44,8 @@ public static void dumpConfigurationDescriptors(final Device device,
4344
final int result = LibUsb.getConfigDescriptor(device, i, descriptor);
4445
if (result < 0)
4546
{
46-
throw new RuntimeException(
47-
"Unable to read config descriptor. Result=" + result);
47+
throw new LibUsbException("Unable to read config descriptor",
48+
result);
4849
}
4950
try
5051
{
@@ -97,8 +98,8 @@ public static void dumpDevice(final Device device)
9798
int result = LibUsb.getDeviceDescriptor(device, descriptor);
9899
if (result < 0)
99100
{
100-
throw new RuntimeException(
101-
"Unable to read device descriptor. Result=" + result);
101+
throw new LibUsbException("Unable to read device descriptor",
102+
result);
102103
}
103104

104105
// Try to open the device. This may fail because user has no
@@ -143,17 +144,15 @@ public static void main(final String[] args)
143144
int result = LibUsb.init(context);
144145
if (result < 0)
145146
{
146-
throw new RuntimeException(
147-
"Unable to initialize libusb. Result=" + result);
147+
throw new LibUsbException("Unable to initialize libusb", result);
148148
}
149149

150150
// Read the USB device list
151151
final DeviceList list = new DeviceList();
152152
result = LibUsb.getDeviceList(context, list);
153153
if (result < 0)
154154
{
155-
throw new RuntimeException(
156-
"Unable to get device list. Result=" + result);
155+
throw new LibUsbException("Unable to get device list", result);
157156
}
158157

159158
try

src/main/java/org/usb4java/examples/ListDevices.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.usb4java.DeviceDescriptor;
1111
import org.usb4java.DeviceList;
1212
import org.usb4java.LibUsb;
13+
import org.usb4java.LibUsbException;
1314

1415
/**
1516
* Simply lists all available USB devices.
@@ -33,17 +34,15 @@ public static void main(String[] args)
3334
int result = LibUsb.init(context);
3435
if (result < 0)
3536
{
36-
throw new RuntimeException(
37-
"Unable to initialize libusb. Result=" + result);
37+
throw new LibUsbException("Unable to initialize libusb", result);
3838
}
3939

4040
// Read the USB device list
4141
DeviceList list = new DeviceList();
4242
result = LibUsb.getDeviceList(context, list);
4343
if (result < 0)
4444
{
45-
throw new RuntimeException(
46-
"Unable to get device list. Result=" + result);
45+
throw new LibUsbException("Unable to get device list", result);
4746
}
4847

4948
try
@@ -57,8 +56,8 @@ public static void main(String[] args)
5756
result = LibUsb.getDeviceDescriptor(device, descriptor);
5857
if (result < 0)
5958
{
60-
throw new RuntimeException(
61-
"Unable to read device descriptor. Result=" + result);
59+
throw new LibUsbException(
60+
"Unable to read device descriptor", result);
6261
}
6362
System.out.format(
6463
"Bus %03d, Device %03d: Vendor %04x, Product %04x%n",

0 commit comments

Comments
 (0)