2
liusuyi
2026-05-12 9b5c9db9189493fbc6db48f55a7b7311b2a3253c
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
package com.ard.common.core.exception.device;
 
/**
 * SDK层设备异常基类(所有设备相关异常的父类)
 */
public class CameraSDKException extends RuntimeException {
    // 异常码(标准化,方便前端/调用方识别)
    private int code;
    // 相机ID(定位具体异常设备)
    private String cameraId;
 
    public CameraSDKException(int code, String cameraId, String message) {
        super(message);
        this.code = code;
        this.cameraId = cameraId;
    }
 
    // GETTER
    public int getCode() { return code; }
    public String getCameraId() { return cameraId; }
 
    // 常用异常码枚举(标准化)
    public enum ErrorCode {
        CAMERA_NOT_EXIST(1001, "相机不存在"),
        CAMERA_OFFLINE(1002, "相机离线"),
        CHANNEL_NOT_EXIST(1003, "通道不存在"),
        CMD_NOT_SUPPORT(1004, "相机不支持该指令"),
        NETWORK_TIMEOUT(1005, "相机网络超时"),
        AUTH_FAILED(1006, "相机登录认证失败"),
        TCP_CONNECT_FAILED(1007, "tcp连接失败"),
        OVER_GUIDANCE_RANGE(1008, "超出引导范围"),
        BEYOND_VISIBILITY_RANGE(1009, "目标位于不可视域范围"),
        CAMERA_MAX_VISIBLE_DISTANCE_NULL(1010,"相机最大可视距离为空");
 
        private final int code;
        private final String msg;
 
        ErrorCode(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
 
        public int getCode() { return code; }
        public String getMsg() { return msg; }
    }
 
    // 快捷创建异常的静态方法(简化开发)
    public static CameraSDKException cameraNotExist(String cameraId) {
        return new CameraSDKException(ErrorCode.CAMERA_NOT_EXIST.getCode(), cameraId, 
                ErrorCode.CAMERA_NOT_EXIST.getMsg() + ":" + cameraId);
    }
 
    public static CameraSDKException cameraOffline(String cameraId) {
        return new CameraSDKException(ErrorCode.CAMERA_OFFLINE.getCode(), cameraId, 
                ErrorCode.CAMERA_OFFLINE.getMsg() + ":" + cameraId);
    }
 
}