Skip to content

Commit f9d2459

Browse files
committed
加入一些 Exception
1 parent 9cc713b commit f9d2459

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/DriveControls/Localizers/definition/SubassemblyLocalizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import com.acmerobotics.roadrunner.Pose2d;
66

7+
import org.firstinspires.ftc.teamcode.utils.Exceptions.UnKnownErrorsException;
8+
79
public abstract class SubassemblyLocalizer implements Localizer{
810
public final LocalizerPlugin[] plugins;
911
public Pose2d RobotPosition;
@@ -45,7 +47,7 @@ public void update(){
4547
++VectorFactor;
4648
++HeadingFactor;
4749
}else{
48-
throw new RuntimeException("unknown localizer plugin");
50+
throw new UnKnownErrorsException("Unknown localizer plugin");
4951
}
5052
}
5153
RobotPosition=new Pose2d(

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/Structure.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.firstinspires.ftc.teamcode.Hardwares.basic.Servos;
1212
import org.firstinspires.ftc.teamcode.RuntimeOption;
1313
import org.firstinspires.ftc.teamcode.utils.Enums.ClipPosition;
14+
import org.firstinspires.ftc.teamcode.utils.Exceptions.UnKnownErrorsException;
1415

1516
public class Structure {
1617
Motors motors;
@@ -62,7 +63,7 @@ public void ClipOption(@NonNull ClipPosition clipPosition){
6263
closeClips();
6364
break;
6465
default:
65-
throw new RuntimeException("UnKnown ClipPosition");
66+
throw new UnKnownErrorsException("UnKnown ClipPosition");
6667
}
6768
}
6869

@@ -79,7 +80,7 @@ public void operateThroughGamePad(@NonNull Gamepad gamepad){
7980
clipPosition=ClipPosition.Open;
8081
break;
8182
default:
82-
throw new RuntimeException("UnKnown ClipPosition");
83+
throw new UnKnownErrorsException("UnKnown ClipPosition");
8384
}
8485
}
8586
}else gamePadButtonBHolding=false;

TeamCode/src/main/java/org/firstinspires/ftc/teamcode/Hardwares/basic/DeviceMap.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.firstinspires.ftc.teamcode.Hardwares.namespace.HardwareDevices;
1313
import org.firstinspires.ftc.teamcode.utils.Enums.HardwareState;
14+
import org.firstinspires.ftc.teamcode.utils.Exceptions.DeviceDisabledException;
1415

1516
import java.util.HashMap;
1617
import java.util.Map;
@@ -37,15 +38,19 @@ public DeviceMap(HardwareMap hardwareMap){
3738
}
3839

3940
public HardwareDevice getDevice(@NonNull HardwareDevices hardwareDevices){
40-
if(hardwareDevices.state==HardwareState.Disabled)throw new RuntimeException("Hardware "+hardwareDevices.name()+" Disabled.");
41+
if(hardwareDevices.state==HardwareState.Disabled) {
42+
throw new DeviceDisabledException(hardwareDevices.name());
43+
}
4144
if(devices.containsKey(hardwareDevices)){
4245
return devices.get(hardwareDevices);
4346
}else{
4447
throw new NullPointerException("Device Not Found:"+ hardwareDevices.toString());
4548
}
4649
}
4750
public void setDirection(@NonNull HardwareDevices hardwareDevices, DcMotorSimple.Direction direction){
48-
if(hardwareDevices.state==HardwareState.Disabled)throw new RuntimeException("Hardware "+hardwareDevices.name()+" Disabled.");
51+
if(hardwareDevices.state==HardwareState.Disabled) {
52+
throw new DeviceDisabledException(hardwareDevices.name());
53+
}
4954
HardwareDevice device=getDevice(hardwareDevices);
5055
if(device instanceof DcMotorEx){
5156
((DcMotorEx) device).setDirection(direction);
@@ -54,7 +59,9 @@ public void setDirection(@NonNull HardwareDevices hardwareDevices, DcMotorSimple
5459
}
5560
}
5661
public void setPower(@NonNull HardwareDevices hardwareDevices, double power){
57-
if(hardwareDevices.state==HardwareState.Disabled)throw new RuntimeException("Hardware "+hardwareDevices.name()+" Disabled.");
62+
if(hardwareDevices.state==HardwareState.Disabled) {
63+
throw new DeviceDisabledException(hardwareDevices.name());
64+
}
5865
HardwareDevice device=getDevice(hardwareDevices);
5966
if(device instanceof DcMotorEx){
6067
((DcMotorEx) device).setPower(power);
@@ -65,7 +72,9 @@ public void setPower(@NonNull HardwareDevices hardwareDevices, double power){
6572
}
6673
}
6774
public void setPosition(@NonNull HardwareDevices hardwareDevices, double position){
68-
if(hardwareDevices.state==HardwareState.Disabled)throw new RuntimeException("Hardware "+hardwareDevices.name()+" Disabled.");
75+
if(hardwareDevices.state==HardwareState.Disabled) {
76+
throw new DeviceDisabledException(hardwareDevices.name());
77+
}
6978
HardwareDevice device=getDevice(hardwareDevices);
7079
if(device instanceof Servo){
7180
((Servo) device).setPosition(position);
@@ -74,7 +83,9 @@ public void setPosition(@NonNull HardwareDevices hardwareDevices, double positio
7483
}
7584
}
7685
public double getPosition(@NonNull HardwareDevices hardwareDevices){
77-
if(hardwareDevices.state==HardwareState.Disabled)throw new RuntimeException("Hardware "+hardwareDevices.name()+" Disabled.");
86+
if(hardwareDevices.state==HardwareState.Disabled) {
87+
throw new DeviceDisabledException(hardwareDevices.name());
88+
}
7889
HardwareDevice device=getDevice(hardwareDevices);
7990
if (device instanceof Servo) {
8091
return ((Servo) device).getPosition();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.firstinspires.ftc.teamcode.utils.Exceptions;
2+
3+
public class DeviceDisabledException extends NullPointerException{
4+
public DeviceDisabledException(String s){
5+
super("Device "+s+" is/are Disabled!");
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.firstinspires.ftc.teamcode.utils.Exceptions;
2+
3+
public class UnKnownErrorsException extends RuntimeException{
4+
public UnKnownErrorsException(String s){
5+
super("UnKnown Enum Type"+s);
6+
}
7+
}

0 commit comments

Comments
 (0)