mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-29 02:21:44 +00:00
Adds a special exception and status message for a handle error (#127)
This commit is contained in:
committed by
Peter Johnson
parent
36ac37db8c
commit
fb865d3ee7
@@ -42,6 +42,7 @@ static jclass runtimeExCls = nullptr;
|
||||
static jclass illegalArgExCls = nullptr;
|
||||
static jclass boundaryExCls = nullptr;
|
||||
static jclass allocationExCls = nullptr;
|
||||
static jclass halHandleExCls = nullptr;
|
||||
static jclass canInvalidBufferExCls = nullptr;
|
||||
static jclass canMessageNotFoundExCls = nullptr;
|
||||
static jclass canMessageNotAllowedExCls = nullptr;
|
||||
@@ -126,12 +127,23 @@ void ThrowAllocationException(JNIEnv *env, int32_t status) {
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void ThrowHalHandleException(JNIEnv *env, int32_t status) {
|
||||
const char *message = getHALErrorMessage(status);
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
sprintf(buf, " Code: $%d. %s", status, message);
|
||||
env->ThrowNew(halHandleExCls, buf);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
void ReportError(JNIEnv *env, int32_t status, bool do_throw) {
|
||||
if (status == 0) return;
|
||||
if (status == NO_AVAILABLE_RESOURCES ||
|
||||
status == RESOURCE_IS_ALLOCATED) {
|
||||
ThrowAllocationException(env, status);
|
||||
}
|
||||
if (status == HAL_HANDLE_ERROR) {
|
||||
ThrowHalHandleException(env, status);
|
||||
}
|
||||
const char *message = getHALErrorMessage(status);
|
||||
if (do_throw && status < 0) {
|
||||
char *buf = new char[strlen(message) + 30];
|
||||
@@ -277,6 +289,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
allocationExCls = static_cast<jclass>(env->NewGlobalRef(local));
|
||||
if (!allocationExCls) return JNI_ERR;
|
||||
env->DeleteLocalRef(local);
|
||||
|
||||
local = env->FindClass("edu/wpi/first/wpilibj/util/HalHandleException");
|
||||
if (!local) return JNI_ERR;
|
||||
halHandleExCls = static_cast<jclass>(env->NewGlobalRef(local));
|
||||
if (!halHandleExCls) return JNI_ERR;
|
||||
env->DeleteLocalRef(local);
|
||||
|
||||
local = env->FindClass("edu/wpi/first/wpilibj/can/CANInvalidBufferException");
|
||||
if (!local) return JNI_ERR;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2008-2016. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.wpilibj.util;
|
||||
|
||||
/**
|
||||
* Exception indicating that an error has occured with a HAL Handle.
|
||||
*/
|
||||
public class HalHandleException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Create a new HalHandleException.
|
||||
*
|
||||
* @param msg the message to attach to the exception
|
||||
*/
|
||||
public HalHandleException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user