]> git.basschouten.com Git - openhab-addons.git/blob
24e8b0c09d75a00e6da1ef32acd4c345a64550d0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.io.transport.modbus.internal;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.io.transport.modbus.exception.ModbusSlaveIOException;
20
21 import net.wimpi.modbus.ModbusIOException;
22
23 /**
24  * Exception for all IO errors
25  *
26  * @author Sami Salonen - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public class ModbusSlaveIOExceptionImpl extends ModbusSlaveIOException {
31
32     private static final long serialVersionUID = -8910463902857643468L;
33     private Exception error;
34
35     public ModbusSlaveIOExceptionImpl(ModbusIOException e) {
36         this.error = e;
37     }
38
39     public ModbusSlaveIOExceptionImpl(IOException e) {
40         this.error = e;
41     }
42
43     @Override
44     public @Nullable String getMessage() {
45         return String.format("Modbus IO Error with cause=%s, EOF=%s, message='%s', cause2=%s",
46                 error.getClass().getSimpleName(),
47                 error instanceof ModbusIOException ? ((ModbusIOException) error).isEOF() : "?", error.getMessage(),
48                 error.getCause());
49     }
50
51     @Override
52     public String toString() {
53         return String.format("ModbusSlaveIOException(cause=%s, EOF=%s, message='%s', cause2=%s)",
54                 error.getClass().getSimpleName(),
55                 error instanceof ModbusIOException ? ((ModbusIOException) error).isEOF() : "?", error.getMessage(),
56                 error.getCause());
57     }
58 }