473,320 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Exception handler...branching without using the stack pointer

JT
We have an exception handler which needs some tweaking because when we
changed compilers, the embedded assembly didn't work. Ideally, we
would like a complete C++ solution, without assembly statements.

One assumption is that the stack pointer may be invalid. So, we attach
a VxWorks exception handler to a method which has no local data and
does not call other methods (and so does not generate code which uses
the stack pointer). This method counts how many times it has been
called to guard against recursive exceptions in the event the stack
pointer is invalid. After the guard code, the method branches (with
embedded assembly) to the address of the entry of another method to
generically handle PowerPC exceptions.

So, is there another way of doing this all in C++? If not, is there
another way of branching using assembly that would be more portable
than using the address of the method.

Thanks

Oct 20 '05 #1
1 1894

"JT" <th*******@sbcglobal.net> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
We have an exception handler which needs some tweaking because when we
changed compilers, the embedded assembly didn't work. Ideally, we
would like a complete C++ solution, without assembly statements.

One assumption is that the stack pointer may be invalid. So, we attach
a VxWorks exception handler to a method which has no local data and
does not call other methods (and so does not generate code which uses
the stack pointer). This method counts how many times it has been
called to guard against recursive exceptions in the event the stack
pointer is invalid. After the guard code, the method branches (with
embedded assembly) to the address of the entry of another method to
generically handle PowerPC exceptions.


This is useless for different compilers. You are digging into compilers
exception handling features and each compiler can do different things.
Simply do this:

jump_buf env;
const int FAILURE = 1;
int main()
{
int indication = setjmp(env); // returns 0 normaly, on FAILURE resets
the stack
// so you can call your
failure handler normaly
if(indication == FAILURE) my_failure_handler();
entry_function();
return 0;
}

and then attach in whichever way your want your handler:

void my_attached_exception_handler(...)
{
static bool failure_state;
if(failure_state == true) longjmp(env,FAILURE); // returns stack to state
before setjmp
}
Greetings, Bane.
Oct 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the...
7
by: Douglas Peterson | last post by:
Take a look at this code, it looks funny as its written to be as short as possible: -- code -- struct Base { ~Base() { *((char*)0) = 0; } }; struct Derived : public Base
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
2
by: Seth | last post by:
Ok, here is my setup. I have a fully functioning HTTP Handler implemented. The handler is supposed to handle every single request that comes in to a particular virtual directory. Thus, in IIS, I...
4
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks...
3
by: bobueland | last post by:
Sometimes the best way to understand something is to understand the mechanism behind it. Maybe that is true for exceptions. This is a model I have right now (which probably is wrong) 1. When a...
12
by: Subhransu Sekhar Sahoo | last post by:
Hi All, I have a doubt in the implementation of C++ try catch exception handling procedure. Whenever there is a through, the execution has to go to the point of catch. Now, if the catch block...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
10
by: Rahul | last post by:
Hi Everyone, I have the following exception class, class E1 { }; class E2 {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.