mirror of
https://github.com/throwtheswitch/cexception.git
synced 2026-08-26 04:59:58 +00:00
* fixed error where fallback function was showing wrong ID
This commit is contained in:
+5
-5
@@ -13,14 +13,14 @@ void Throw(CEXCEPTION_T ExceptionID)
|
|||||||
{
|
{
|
||||||
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
|
||||||
}
|
}
|
||||||
CEXCEPTION_NO_CATCH_HANDLER(MY_ID);
|
CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Explanation of what it's all for:
|
// Explanation of what it's all for:
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
/*
|
/*
|
||||||
#define Try
|
#define Try
|
||||||
{ <- give us some local scope. most compilers are happy with this
|
{ <- give us some local scope. most compilers are happy with this
|
||||||
jmp_buf *PrevFrame, NewFrame; <- prev frame points to the last try block's frame. new frame gets created on stack for this Try block
|
jmp_buf *PrevFrame, NewFrame; <- prev frame points to the last try block's frame. new frame gets created on stack for this Try block
|
||||||
unsigned int MY_ID = CEXCEPTION_GET_ID; <- look up this task's id for use in frame array. always 0 if single-tasking
|
unsigned int MY_ID = CEXCEPTION_GET_ID; <- look up this task's id for use in frame array. always 0 if single-tasking
|
||||||
@@ -30,12 +30,12 @@ void Throw(CEXCEPTION_T ExceptionID)
|
|||||||
if (setjmp(NewFrame) == 0) { <- do setjmp. it returns 1 if longjump called, otherwise 0
|
if (setjmp(NewFrame) == 0) { <- do setjmp. it returns 1 if longjump called, otherwise 0
|
||||||
if (&PrevFrame) <- this is here to force proper scoping. it requires braces or a single line to be but after Try, otherwise won't compile. This is always true at this point.
|
if (&PrevFrame) <- this is here to force proper scoping. it requires braces or a single line to be but after Try, otherwise won't compile. This is always true at this point.
|
||||||
|
|
||||||
#define Catch(e)
|
#define Catch(e)
|
||||||
else { } <- this also forces proper scoping. Without this they could stick their own 'else' in and it would get ugly
|
else { } <- this also forces proper scoping. Without this they could stick their own 'else' in and it would get ugly
|
||||||
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- no errors happened, so just set the exception id to NONE (in case it was corrupted)
|
CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- no errors happened, so just set the exception id to NONE (in case it was corrupted)
|
||||||
}
|
}
|
||||||
else <- an exception occurred
|
else <- an exception occurred
|
||||||
{ e = CExceptionFrames[MY_ID].Exception; e=e;} <- assign the caught exception id to the variable passed in.
|
{ e = CExceptionFrames[MY_ID].Exception; e=e;} <- assign the caught exception id to the variable passed in.
|
||||||
CExceptionFrames[MY_ID].pFrame = PrevFrame; <- make the pointer in the array point at the previous frame again, as if NewFrame never existed.
|
CExceptionFrames[MY_ID].pFrame = PrevFrame; <- make the pointer in the array point at the previous frame again, as if NewFrame never existed.
|
||||||
} <- finish off that local scope we created to have our own variables
|
} <- finish off that local scope we created to have our own variables
|
||||||
if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE) <- start the actual 'catch' processing if we have an exception id saved away
|
if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE) <- start the actual 'catch' processing if we have an exception id saved away
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
extern volatile int TestingTheFallback;
|
extern volatile int TestingTheFallback;
|
||||||
|
extern volatile int TestingTheFallbackId;
|
||||||
|
|
||||||
//Optionally define the exception type (something like an int which can be directly assigned)
|
//Optionally define the exception type (something like an int which can be directly assigned)
|
||||||
#define CEXCEPTION_T int
|
#define CEXCEPTION_T int
|
||||||
@@ -20,6 +21,7 @@ extern volatile int TestingTheFallback;
|
|||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
|
TestingTheFallbackId = id; \
|
||||||
TestingTheFallback--; \
|
TestingTheFallback--; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "CException.h"
|
#include "CException.h"
|
||||||
|
|
||||||
volatile int TestingTheFallback;
|
volatile int TestingTheFallback;
|
||||||
|
volatile int TestingTheFallbackId;
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
@@ -314,6 +315,7 @@ void test_AThrowWithoutATryCatchWillUseDefaultHandlerIfSpecified(void)
|
|||||||
|
|
||||||
//We know the fallback was run because it decrements the counter above
|
//We know the fallback was run because it decrements the counter above
|
||||||
TEST_ASSERT_FALSE(TestingTheFallback);
|
TEST_ASSERT_FALSE(TestingTheFallback);
|
||||||
|
TEST_ASSERT_EQUAL(0xBE, TestingTheFallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_AThrowWithoutOutsideATryCatchWillUseDefaultHandlerEvenAfterTryCatch(void)
|
void test_AThrowWithoutOutsideATryCatchWillUseDefaultHandlerEvenAfterTryCatch(void)
|
||||||
@@ -336,4 +338,5 @@ void test_AThrowWithoutOutsideATryCatchWillUseDefaultHandlerEvenAfterTryCatch(vo
|
|||||||
|
|
||||||
//We know the fallback was run because it decrements the counter above
|
//We know the fallback was run because it decrements the counter above
|
||||||
TEST_ASSERT_FALSE(TestingTheFallback);
|
TEST_ASSERT_FALSE(TestingTheFallback);
|
||||||
}
|
TEST_ASSERT_EQUAL(0xBE, TestingTheFallbackId);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user