Skip to content
This repository was archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
move handleCapturedInterrupt etc back to internal
Browse files Browse the repository at this point in the history
Former-commit-id: 7d022f7aee18106896083f3113a8c9028c98b278
Former-commit-id: 00dd01d
  • Loading branch information
rgatkinson committed Oct 14, 2015
1 parent 9504ea5 commit 141f8c6
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,6 @@ public static RuntimeException wrap(Exception e)
return new RuntimeException(e);
}

//----------------------------------------------------------------------------------------------
// Dealing with captured exceptions
//
// That InterruptedException is a non-runtime exception is, I believe, a bug: I could go
// on at great length here about that, but for the moment will refrain and defer until another
// time: the issue is a lengthy discussion.
//
// But we have the issue of what to do. That the fellow has captured the interrupt means that
// he doesn't want an InterruptedException to propagate. Yet somehow we must in effect do so:
// the thread needs to be torn down. Ergo, we seem to have no choice but to throw a runtime
// version of the interrupt.
//----------------------------------------------------------------------------------------------

public static void handleCapturedInterrupt(InterruptedException e)
{
handleCapturedException((Exception)e);
}

public static void handleCapturedException(Exception e)
{
if (e instanceof InterruptedException || e instanceof RuntimeInterruptedException);
Thread.currentThread().interrupt();

throw wrap(e);
}

//----------------------------------------------------------------------------------------------
// Construction
//----------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ private void delayLore(int ms)
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
handleCapturedInterrupt(e);
}
}

Expand All @@ -733,7 +733,7 @@ private void delay(int ms)
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
handleCapturedInterrupt(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.swerverobotics.library.internal;

import org.swerverobotics.library.exceptions.*;

/**
* A class that helps us start a thread and interlock with its actual starting up.
*
Expand Down Expand Up @@ -80,7 +78,7 @@ public synchronized void start()
this.started = true; // so stop() will work
stop();

SwerveRuntimeException.handleCapturedException(e);
Util.handleCapturedException(e);
}
}

Expand Down Expand Up @@ -112,7 +110,7 @@ public synchronized void stop(int msWait)
}
catch (Exception e)
{
SwerveRuntimeException.handleCapturedException(e);
Util.handleCapturedException(e);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void disarm()
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
handleCapturedInterrupt(e);
}
}

Expand Down Expand Up @@ -442,7 +442,7 @@ public void close()
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
handleCapturedInterrupt(e);

// Can't return (no data to return!) so we must throw
throw SwerveRuntimeException.wrap(e);
Expand Down Expand Up @@ -522,7 +522,7 @@ public void close()
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
handleCapturedInterrupt(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.qualcomm.robotcore.exception.RobotCoreException;
import com.qualcomm.robotcore.robocol.Command;

import org.swerverobotics.library.exceptions.SwerveRuntimeException;

import java.util.concurrent.Semaphore;

/**
Expand Down Expand Up @@ -47,7 +45,7 @@ public void init(EventLoopManager eventLoopManager) throws RobotCoreException, I
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
Util.handleCapturedInterrupt(e);
}
super.processCommand(command);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public T doUntrackedReadOperation(IInterruptableRunnable actionBeforeDispatch)
// Our signature (and that of our caller) doesn't allow us to throw
// InterruptedException. But we can't actually return a value to our caller,
// as we have nothing to return. So, we do the best we can, and throw SOMETHING.
SwerveRuntimeException.handleCapturedException(e);
Util.handleCapturedException(e);
}
return this.result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.swerverobotics.library.internal;

import org.swerverobotics.library.exceptions.*;
import org.swerverobotics.library.interfaces.*;

/**
Expand Down Expand Up @@ -52,7 +51,7 @@ protected void doUntrackedWriteOperation(IInterruptableRunnable actionBeforeDisp
}
catch (Exception e)
{
SwerveRuntimeException.handleCapturedException(e);
Util.handleCapturedException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.qualcomm.robotcore.hardware.*;
import org.swerverobotics.library.*;
import org.swerverobotics.library.exceptions.*;

/**
* An implementation of DcMotorController that talks to a non-thunking target implementation
Expand Down Expand Up @@ -174,7 +173,7 @@ private void waitForWritesToChannelToDrain(int channel)
}
catch (InterruptedException e)
{
SwerveRuntimeException.handleCapturedInterrupt(e);
Util.handleCapturedInterrupt(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,30 @@ static public void setPrivateDoubleField(Object target, int iField, double value
throw SwerveRuntimeException.wrap(e);
}
}

//----------------------------------------------------------------------------------------------
// Dealing with captured exceptions
//
// That InterruptedException is a non-runtime exception is, I believe, a bug: I could go
// on at great length here about that, but for the moment will refrain and defer until another
// time: the issue is a lengthy discussion.
//
// But we have the issue of what to do. That the fellow has captured the interrupt means that
// he doesn't want an InterruptedException to propagate. Yet somehow we must in effect do so:
// the thread needs to be torn down. Ergo, we seem to have no choice but to throw a runtime
// version of the interrupt.
//----------------------------------------------------------------------------------------------

public static void handleCapturedInterrupt(InterruptedException e)
{
handleCapturedException((Exception)e);
}

public static void handleCapturedException(Exception e)
{
if (e instanceof InterruptedException || e instanceof RuntimeInterruptedException);
Thread.currentThread().interrupt();

throw SwerveRuntimeException.wrap(e);
}
}

0 comments on commit 141f8c6

Please sign in to comment.