mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
Throw UncleanStatusException rather then RuntimeException (#1114)
This commit is contained in:
committed by
Peter Johnson
parent
85fe722f4c
commit
d9971a705a
@@ -45,7 +45,6 @@ TLogLevel halUtilLogLevel = logWARNING;
|
||||
#define kRIOStatusResourceNotInitialized -52010
|
||||
|
||||
static JavaVM* jvm = nullptr;
|
||||
static JException runtimeExCls;
|
||||
static JException illegalArgExCls;
|
||||
static JException boundaryExCls;
|
||||
static JException allocationExCls;
|
||||
@@ -69,7 +68,6 @@ static const JClassInit classes[] = {
|
||||
{"edu/wpi/first/wpilibj/CANData", &canDataCls}};
|
||||
|
||||
static const JExceptionInit exceptions[] = {
|
||||
{"java/lang/RuntimeException", &runtimeExCls},
|
||||
{"java/lang/IllegalArgumentException", &illegalArgExCls},
|
||||
{"edu/wpi/first/wpilibj/util/BoundaryException", &boundaryExCls},
|
||||
{"edu/wpi/first/wpilibj/util/AllocationException", &allocationExCls},
|
||||
@@ -86,6 +84,17 @@ static const JExceptionInit exceptions[] = {
|
||||
|
||||
namespace frc {
|
||||
|
||||
void ThrowUncleanStatusException(JNIEnv* env, wpi::StringRef msg,
|
||||
int32_t status) {
|
||||
static jmethodID func =
|
||||
env->GetMethodID(uncleanStatusExCls, "<init>", "(ILjava/lang/String;)V");
|
||||
|
||||
jobject exception =
|
||||
env->NewObject(uncleanStatusExCls, func, static_cast<jint>(status),
|
||||
MakeJString(env, msg));
|
||||
env->Throw(static_cast<jthrowable>(exception));
|
||||
}
|
||||
|
||||
void ThrowAllocationException(JNIEnv* env, int32_t minRange, int32_t maxRange,
|
||||
int32_t requestedValue, int32_t status) {
|
||||
const char* message = HAL_GetErrorMessage(status);
|
||||
@@ -116,7 +125,7 @@ void ReportError(JNIEnv* env, int32_t status, bool doThrow) {
|
||||
wpi::SmallString<1024> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
runtimeExCls.Throw(env, buf.c_str());
|
||||
ThrowUncleanStatusException(env, buf.c_str(), status);
|
||||
} else {
|
||||
std::string func;
|
||||
auto stack = GetJavaStackTrace(env, &func, "edu.wpi.first.wpilibj");
|
||||
@@ -138,7 +147,7 @@ void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange,
|
||||
wpi::SmallString<1024> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
oss << " Code: " << status << ". " << message;
|
||||
runtimeExCls.Throw(env, buf.c_str());
|
||||
ThrowUncleanStatusException(env, buf.c_str(), status);
|
||||
}
|
||||
|
||||
void ReportCANError(JNIEnv* env, int32_t status, int message_id) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.hal.SolenoidJNI;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.util.UncleanStatusException;
|
||||
|
||||
/**
|
||||
* DoubleSolenoid class for running 2 channels of high voltage Digital Output on the PCM.
|
||||
@@ -64,7 +65,7 @@ public class DoubleSolenoid extends SolenoidBase {
|
||||
try {
|
||||
portHandle = HAL.getPortWithModule((byte) m_moduleNumber, (byte) reverseChannel);
|
||||
m_reverseHandle = SolenoidJNI.initializeSolenoidPort(portHandle);
|
||||
} catch (RuntimeException ex) {
|
||||
} catch (UncleanStatusException ex) {
|
||||
// free the forward handle on exception, then rethrow
|
||||
SolenoidJNI.freeSolenoidPort(m_forwardHandle);
|
||||
m_forwardHandle = 0;
|
||||
|
||||
@@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.hal.RelayJNI;
|
||||
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
|
||||
import edu.wpi.first.wpilibj.util.UncleanStatusException;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@@ -149,12 +150,12 @@ public class Relay extends SendableBase implements MotorSafety {
|
||||
private void freeRelay() {
|
||||
try {
|
||||
RelayJNI.setRelay(m_forwardHandle, false);
|
||||
} catch (RuntimeException ex) {
|
||||
} catch (UncleanStatusException ex) {
|
||||
// do nothing. Ignore
|
||||
}
|
||||
try {
|
||||
RelayJNI.setRelay(m_reverseHandle, false);
|
||||
} catch (RuntimeException ex) {
|
||||
} catch (UncleanStatusException ex) {
|
||||
// do nothing. Ignore
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user