-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathLibUsbException.java
More file actions
60 lines (54 loc) · 1.5 KB
/
LibUsbException.java
File metadata and controls
60 lines (54 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright 2014 Klaus Reimer <[email protected]>
* See LICENSE.md for licensing information.
*/
package org.usb4java;
/**
* A runtime exception which automatically outputs the libusb error string.
*
* @author Klaus Reimer ([email protected])
*/
public final class LibUsbException extends RuntimeException
{
/** Serial version UID. */
private static final long serialVersionUID = 1L;
/** The libusb error code. */
private final int errorCode;
/**
* Constructs a libusb exception which just outputs the error code and
* the error message from libusb.
*
* @param errorCode
* The error code.
*/
public LibUsbException(final int errorCode)
{
super(String.format("USB error %d: %s", -errorCode,
LibUsb.strError(errorCode)));
this.errorCode = errorCode;
}
/**
* Constructs a libusb exception which outputs the error code and
* the error message from libusb together with a custom error message.
*
* @param message
* The error message.
* @param errorCode
* The error code.
*/
public LibUsbException(final String message, final int errorCode)
{
super(String.format("USB error %d: %s: %s", -errorCode, message,
LibUsb.strError(errorCode)));
this.errorCode = errorCode;
}
/**
* Returns the error code.
*
* @return The error code
*/
public int getErrorCode()
{
return this.errorCode;
}
}