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