mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
@@ -154,7 +154,7 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Report error to Driver Station. Also prints error to System.err Optionally appends Stack trace
|
||||
* Report error to Driver Station. Optionally appends Stack trace
|
||||
* to error message.
|
||||
*
|
||||
* @param printTrace If true, append stack trace to error string
|
||||
@@ -164,7 +164,17 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Report warning to Driver Station. Also prints error to System.err Optionally appends Stack
|
||||
* Report error to Driver Station. Appends provided stack trace
|
||||
* to error message.
|
||||
*
|
||||
* @param stackTrace The stack trace to append
|
||||
*/
|
||||
public static void reportError(String error, StackTraceElement[] stackTrace) {
|
||||
reportErrorImpl(true, 1, error, stackTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report warning to Driver Station. Optionally appends Stack
|
||||
* trace to warning message.
|
||||
*
|
||||
* @param printTrace If true, append stack trace to warning string
|
||||
@@ -173,27 +183,46 @@ public class DriverStation implements RobotState.Interface {
|
||||
reportErrorImpl(false, 1, error, printTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report warning to Driver Station. Appends provided stack
|
||||
* trace to warning message.
|
||||
*
|
||||
* @param stackTrace The stack trace to append
|
||||
*/
|
||||
public static void reportWarning(String error, StackTraceElement[] stackTrace) {
|
||||
reportErrorImpl(false, 1, error, stackTrace);
|
||||
}
|
||||
|
||||
private static void reportErrorImpl(boolean isError, int code, String error, boolean
|
||||
printTrace) {
|
||||
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
|
||||
reportErrorImpl(isError, code, error, printTrace, Thread.currentThread().getStackTrace(), 3);
|
||||
}
|
||||
|
||||
private static void reportErrorImpl(boolean isError, int code, String error,
|
||||
StackTraceElement[] stackTrace) {
|
||||
reportErrorImpl(isError, code, error, true, stackTrace, 0);
|
||||
}
|
||||
|
||||
private static void reportErrorImpl(boolean isError, int code, String error,
|
||||
boolean printTrace, StackTraceElement[] stackTrace, int stackTraceFirst) {
|
||||
String locString;
|
||||
if (traces.length > 3) {
|
||||
locString = traces[3].toString();
|
||||
if (stackTrace.length >= stackTraceFirst + 1) {
|
||||
locString = stackTrace[stackTraceFirst].toString();
|
||||
} else {
|
||||
locString = "";
|
||||
}
|
||||
boolean haveLoc = false;
|
||||
String traceString = " at ";
|
||||
for (int i = 3; i < traces.length; i++) {
|
||||
String loc = traces[i].toString();
|
||||
traceString += loc + "\n";
|
||||
String traceString = "";
|
||||
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
|
||||
String loc = stackTrace[i].toString();
|
||||
traceString += "\tat " + loc + "\n";
|
||||
// get first user function
|
||||
if (!haveLoc && !loc.startsWith("edu.wpi.first.wpilibj")) {
|
||||
if (!haveLoc && !loc.startsWith("edu.wpi.first")) {
|
||||
locString = loc;
|
||||
haveLoc = true;
|
||||
}
|
||||
}
|
||||
HAL.sendError(isError, code, false, error, locString, printTrace ? traceString : "", true);
|
||||
HAL.sendError(isError, code, false, error, locString, printTrace ? traceString : "", false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.Manifest;
|
||||
//import org.opencv.core.Core;
|
||||
@@ -223,10 +222,14 @@ public abstract class RobotBase {
|
||||
try {
|
||||
robot = (RobotBase) Class.forName(robotName).newInstance();
|
||||
} catch (Throwable throwable) {
|
||||
DriverStation.reportError("ERROR Unhandled exception instantiating robot " + robotName + " "
|
||||
+ throwable.toString() + " at " + Arrays.toString(throwable.getStackTrace()), false);
|
||||
System.err.println("WARNING: Robots don't quit!");
|
||||
System.err.println("ERROR: Could not instantiate robot " + robotName + "!");
|
||||
Throwable cause = throwable.getCause();
|
||||
if (cause != null) {
|
||||
throwable = cause;
|
||||
}
|
||||
DriverStation.reportError("Unhandled exception instantiating robot " + robotName + " "
|
||||
+ throwable.toString(), throwable.getStackTrace());
|
||||
DriverStation.reportWarning("Robots should not quit, but yours did!", false);
|
||||
DriverStation.reportError("Could not instantiate robot " + robotName + "!", false);
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
@@ -253,19 +256,22 @@ public abstract class RobotBase {
|
||||
try {
|
||||
robot.startCompetition();
|
||||
} catch (Throwable throwable) {
|
||||
DriverStation.reportError(
|
||||
"ERROR Unhandled exception: " + throwable.toString() + " at "
|
||||
+ Arrays.toString(throwable.getStackTrace()), false);
|
||||
Throwable cause = throwable.getCause();
|
||||
if (cause != null) {
|
||||
throwable = cause;
|
||||
}
|
||||
DriverStation.reportError("Unhandled exception: " + throwable.toString(),
|
||||
throwable.getStackTrace());
|
||||
errorOnExit = true;
|
||||
} finally {
|
||||
// startCompetition never returns unless exception occurs....
|
||||
System.err.println("WARNING: Robots don't quit!");
|
||||
DriverStation.reportWarning("Robots should not quit, but yours did!", false);
|
||||
if (errorOnExit) {
|
||||
System.err
|
||||
.println("---> The startCompetition() method (or methods called by it) should have "
|
||||
+ "handled the exception above.");
|
||||
DriverStation.reportError(
|
||||
"The startCompetition() method (or methods called by it) should have "
|
||||
+ "handled the exception above.", false);
|
||||
} else {
|
||||
System.err.println("---> Unexpected return from startCompetition() method.");
|
||||
DriverStation.reportError("Unexpected return from startCompetition() method.", false);
|
||||
}
|
||||
}
|
||||
System.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user