2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.linuxinput.internal.evdev4j;
15 import static org.openhab.binding.linuxinput.internal.evdev4j.Utils.constantFromInt;
17 import java.text.MessageFormat;
18 import java.util.Optional;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import jnr.constants.platform.linux.Errno;
23 import jnr.posix.POSIX;
26 * Exception wrapping an operating system errno.
28 * @author Thomas Weißschuh - Initial contribution
31 public class LastErrorException extends RuntimeException {
32 private static final long serialVersionUID = 3112920209797990207L;
33 private final int errno;
35 LastErrorException(POSIX posix, int errno) {
36 super("Error " + errno + ": " + posix.strerror(errno));
40 LastErrorException(POSIX posix, int errno, String detail) {
41 super(MessageFormat.format("Error ({0}) for {1}: {2}", errno, detail, posix.strerror(errno)));
45 public int getErrno() {
49 public Optional<Errno> getError() {
50 return constantFromInt(Errno.values(), errno);