]> git.basschouten.com Git - openhab-addons.git/blob
76a2db0f3daebc031a503a505804ebff631f4f07
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.linuxinput.internal.evdev4j;
14
15 import static org.openhab.binding.linuxinput.internal.evdev4j.Utils.constantFromInt;
16
17 import java.text.MessageFormat;
18 import java.util.Optional;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21
22 import jnr.constants.platform.linux.Errno;
23 import jnr.posix.POSIX;
24
25 /**
26  * Exception wrapping an operating system errno.
27  *
28  * @author Thomas Weißschuh - Initial contribution
29  */
30 @NonNullByDefault
31 public class LastErrorException extends RuntimeException {
32     private static final long serialVersionUID = 3112920209797990207L;
33     private final int errno;
34
35     LastErrorException(POSIX posix, int errno) {
36         super("Error " + errno + ": " + posix.strerror(errno));
37         this.errno = errno;
38     }
39
40     LastErrorException(POSIX posix, int errno, String detail) {
41         super(MessageFormat.format("Error ({0}) for {1}: {2}", errno, detail, posix.strerror(errno)));
42         this.errno = errno;
43     }
44
45     public int getErrno() {
46         return errno;
47     }
48
49     public Optional<Errno> getError() {
50         return constantFromInt(Errno.values(), errno);
51     }
52 }