Hi folks!
I'm using gcc 4.2.3 and glibc6 2.7.
I'm doing an exception handling implementation for a library. Although I
assume to have it done properly, with a handler set up, it exits the program
with a random exit value, and without a handler set up, it crashes with a
SIGSEGV, but as I have found out with gdb, at the same line of code:
__libc_siglongj mp (env=0xbfb935f0 , val=1) at longjmp.c:29
29 {
31 _longjmp_unwind (env, val);
_longjmp_unwind (env=0xbfb935f0 , val=1) at
../nptl/sysdeps/unix/sysv/linux/jmp-unwind.c:32
32 if (__libc_pthread _functions_init )
39 }
__libc_siglongj mp (env=0xbfb935f0 , val=1) at longjmp.c:33
33 if (env[0].__mask_was_sav ed)
39 __longjmp (env[0].__jmpbuf, val ?: 1);
The types i use are:
typedef struct ExcType ExcType;
typedef struct ExcVal ExcVal;
typedef struct Exception Exception;
struct ExcType {
const char *name;
};
union ExcVal {
void* None;
int Int;
char* Char;
};
typedef enum {
NoneType,
IntType,
CharType
} Datatype;
struct Exception {
ExcType *tp;
ExcVal *val;
Datatype dt;
};
struct ExcEntry {
ExcEntry *prev,*next;
jmp_buf buf;
Exception *exc;
};
extern ExcEntry *currexc;
My macros for doing exception handling are as follows:
#define try \
{\
Exception exc;\
ExcEntry excn;\
excn.exc=&exc; excn.prev=curre xc;\
currexc = excn.prev->next = &excn;\
if ( setjmp(excn.buf )==0 )
#define catch(e) \
Exception *e = &exc;\
for (;0;currexc=cur rexc->prev)
#define exctype(et, action) \
if ( e->tp==&et ) { action; }
#define endtry }
#define throw(t,vl) \
{currexc->exc->tp=NULL;\
currexc->exc->tp=&t;\
currexc->exc->val->Char=(char*)vl ;\
currexc->exc->dt=CharType; \
jmp_buf buf;\
memcpy((void*)& buf,(void*)curr exc->buf, sizeof(jmp_buf) );\
longjmp(buf,1); }
A sample program could be:
#include <stdio.h>
ExcType RuntimeError;
int main(int argc, char **argv)
{
try {
throw(RuntimeEr ror,"test error");
} catch(e) {
fprintf(stderr, "foobar!\n" );
exit(42);
} endtry;
}
I don't see where the problem is. Any professional here who can help me?
Greetings,
Fabiano 12 1702
On 2008-09-08, Fabiano Sidler <fa***********@ my-mail.chwrote:
Hi folks!
I'm using gcc 4.2.3 and glibc6 2.7.
I'm doing an exception handling implementation for a library. Although I
assume to have it done properly, with a handler set up, it exits the program
with a random exit value, and without a handler set up, it crashes with a
SIGSEGV, but as I have found out with gdb, at the same line of code:
__libc_siglongj mp (env=0xbfb935f0 , val=1) at longjmp.c:29
29 {
31 _longjmp_unwind (env, val);
_longjmp_unwind (env=0xbfb935f0 , val=1) at
../nptl/sysdeps/unix/sysv/linux/jmp-unwind.c:32
32 if (__libc_pthread _functions_init )
39 }
__libc_siglongj mp (env=0xbfb935f0 , val=1) at longjmp.c:33
33 if (env[0].__mask_was_sav ed)
39 __longjmp (env[0].__jmpbuf, val ?: 1);
The types i use are:
typedef struct ExcType ExcType;
typedef struct ExcVal ExcVal;
typedef struct Exception Exception;
struct ExcType {
const char *name;
};
union ExcVal {
void* None;
int Int;
char* Char;
};
typedef enum {
NoneType,
IntType,
CharType
} Datatype;
struct Exception {
ExcType *tp;
ExcVal *val;
Datatype dt;
};
struct ExcEntry {
ExcEntry *prev,*next;
jmp_buf buf;
Exception *exc;
};
extern ExcEntry *currexc;
Where is this defined? You appear to use it without ever
defining it. Does this program link successfully?
>
My macros for doing exception handling are as follows:
#define try \
{\
Exception exc;\
ExcEntry excn;\
excn.exc=&exc; excn.prev=curre xc;\
currexc = excn.prev->next = &excn;\
if ( setjmp(excn.buf )==0 )
#define catch(e) \
Exception *e = &exc;\
for (;0;currexc=cur rexc->prev)
#define exctype(et, action) \
if ( e->tp==&et ) { action; }
#define endtry }
#define throw(t,vl) \
{currexc->exc->tp=NULL;\
currexc->exc->tp=&t;\
currexc->exc->val->Char=(char*)vl ;\
currexc->exc->dt=CharType; \
jmp_buf buf;\
memcpy((void*)& buf,(void*)curr exc->buf, sizeof(jmp_buf) );\
longjmp(buf,1); }
A sample program could be:
#include <stdio.h>
ExcType RuntimeError;
int main(int argc, char **argv)
{
try {
throw(RuntimeEr ror,"test error");
} catch(e) {
fprintf(stderr, "foobar!\n" );
exit(42);
} endtry;
}
I don't see where the problem is. Any professional here who can help me?
Greetings,
Fabiano
--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
On 2008-09-08, Andrew Poelstra <ap*******@supe rnova.homewrote :
Where is this defined?
jmp_buf is defined in setjmp.h which is, in turn, an ANSI C header.
Maybe i should have written this...in my program, it is included.
Does this program link successfully?
<setjmp.hmust be included and the definitions (and the declaration)
must be done before main(), but then it does, otherwise it couldn't SEGSEGV
here...;)
Greetings,
Fabiano
On 2008-09-08, Fabiano Sidler <fa***********@ my-mail.chwrote:
On 2008-09-08, Andrew Poelstra <ap*******@supe rnova.homewrote :
>Where is this defined?
jmp_buf is defined in setjmp.h which is, in turn, an ANSI C header.
Maybe i should have written this...in my program, it is included.
Sure, but jmp_buf is just a member of the currexc object, for
which storage is never allocated (since this object is not
defined, as far as I can tell).
>Does this program link successfully?
<setjmp.hmus t be included and the definitions (and the declaration)
must be done before main(), but then it does, otherwise it couldn't SEGSEGV
here...;)
--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Andrew Poelstra <ap*******@supe rnova.homewrite s:
On 2008-09-08, Fabiano Sidler <fa***********@ my-mail.chwrote:
>On 2008-09-08, Andrew Poelstra <ap*******@supe rnova.homewrote :
>>Where is this defined?
jmp_buf is defined in setjmp.h which is, in turn, an ANSI C header. Maybe i should have written this...in my program, it is included.
Sure, but jmp_buf is just a member of the currexc object, for
which storage is never allocated (since this object is not
defined, as far as I can tell).
Here's the relevant code from the original article:
| struct ExcEntry {
| ExcEntry *prev,*next;
| jmp_buf buf;
| Exception *exc;
| };
| extern ExcEntry *currexc;
jmp_buf is a type, declared in the standard header <setjmp.h>. The
point is simply that you can't refer to the name "jmp_buf" unless you
have a "#include <setjmp.h>".
buf, on the other hand, is a member of the type struct ExcEntry; that
member is of type jmp_buf. And currexc is a pointer to struct
ExcEntry. So buf (not jmp_buf) is a member of *currexc (not currexc).
[...]
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
On 2008-09-09, Keith Thompson <ks***@mib.orgw rote:
Andrew Poelstra <ap*******@supe rnova.homewrite s:
>On 2008-09-08, Fabiano Sidler <fa***********@ my-mail.chwrote:
>>On 2008-09-08, Andrew Poelstra <ap*******@supe rnova.homewrote : Where is this defined?
jmp_buf is defined in setjmp.h which is, in turn, an ANSI C header. Maybe i should have written this...in my program, it is included. Sure, but jmp_buf is just a member of the currexc object, for which storage is never allocated (since this object is not defined, as far as I can tell).
Here's the relevant code from the original article: | struct ExcEntry { | ExcEntry *prev,*next; | jmp_buf buf; | Exception *exc; | }; | extern ExcEntry *currexc;
jmp_buf is a type, declared in the standard header <setjmp.h>. The
point is simply that you can't refer to the name "jmp_buf" unless you
have a "#include <setjmp.h>".
buf, on the other hand, is a member of the type struct ExcEntry; that
member is of type jmp_buf. And currexc is a pointer to struct
ExcEntry. So buf (not jmp_buf) is a member of *currexc (not currexc).
[...]
But currexc is declared as extern and never defined, so when is
storage set aside for the pointer itself?
(But you are right, I missed that currexc was a pointer.)
--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Fabiano Sidler <fabianosid...@ my-mail.chwrote:
I'm doing an exception handling implementation for a
library. ...
The types i use are:
typedef struct ExcType ExcType;
typedef struct ExcVal ExcVal;
typedef struct Exception Exception;
struct ExcType {
* * * * const char *name;};
union ExcVal {
* * * * void* None;
* * * * int Int;
* * * * char* Char;};
typedef enum {
* * * * NoneType,
* * * * IntType,
* * * * CharType} Datatype;
struct Exception {
* * * * ExcType *tp;
* * * * ExcVal *val;
* * * * Datatype dt;};
struct ExcEntry {
* * * * ExcEntry *prev,*next;
* * * * jmp_buf buf;
* * * * Exception *exc;};
extern ExcEntry *currexc;
My macros for doing exception handling are as follows:
#define try \
* * * * {\
* * * * * * * * Exception exc;\
* * * * * * * * ExcEntry excn;\
* * * * * * * * excn.exc=&exc; excn.prev=curre xc;\
Are you sure currexc is not a null pointer?
* * * * * * * * currexc = excn.prev->next = &excn;\
If it is, this line is problematic.
* * * * * * * * if ( setjmp(excn.buf )==0 )
#define catch(e) \
* * * * * * * * Exception *e = &exc;\
Seems to be missing an 'else' for the above 'if'. Also,
I prefer to insert the { } blocks directly (split across
the macros,) rather than relying on the user to supply
them.
* * * * * * * * for (;0;currexc=cur rexc->prev)
#define exctype(et, action) \
* * * * * * * * * * * * if ( e->tp==&et ) { action; }
#define endtry *}
#define throw(t,vl) \
* * * * {currexc->exc->tp=NULL;\
* * * * currexc->exc->tp=&t;\
* * * * currexc->exc->val->Char=(char*)vl ;\
* * * * currexc->exc->dt=CharType; \
* * * * jmp_buf buf;\
* * * * memcpy((void*)& buf,(void*)curr exc->buf, sizeof(jmp_buf) );\
* * * * longjmp(buf,1); }
A sample program could be:
#include <stdio.h>
ExcType RuntimeError;
int main(int argc, char **argv)
{
* * * * try {
* * * * * * * * throw(RuntimeEr ror,"test error");
* * * * } catch(e) {
* * * * * * * * fprintf(stderr, "foobar!\n" );
* * * * * * * * exit(42);
* * * * } endtry;
}
I don't see where the problem is. Any professional here who can help me?
Greetings,
Fabiano
I _do_ include setjmp.h, this is not the problem...i don't get errors
due to that, anyway! ;)
Greetings,
Fabiano
On 2008-09-09, Peter Nilsson <ai***@acay.com .auwrote:
Are you sure currexc is not a null pointer?
currexc is initialized as follows:
ExcEntry *currexc = &(ExcEntry) {
NULL,
NULL,
{0},
&(Exception) {
NULL,
&(ExcVal) { 0 },
0
}
};
And yes, this is valid C, C99! ;)
Your other points i'm working on right now...:)
Thanks in advance,
Fabiano
Here is the complete demo program:
--- snip ---
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
typedef struct ExcType ExcType;
typedef union ExcVal ExcVal;
typedef struct Exception Exception;
typedef struct ExcEntry ExcEntry;
struct ExcType {
const char *name;
};
union ExcVal {
void* None;
int Int;
char* Char;
};
typedef enum {
NoneType,
IntType,
CharType
} Datatype;
struct Exception {
ExcType *tp;
ExcVal *val;
Datatype dt;
};
struct ExcEntry {
ExcEntry *prev,*next;
jmp_buf buf;
Exception *exc;
};
ExcEntry *currexc = &(ExcEntry) {
NULL,
NULL,
{0},
&(Exception) {
NULL, &(ExcVal){0} , 0
}
};
#define try \
{\
Exception exc;\
ExcEntry excn;\
excn.exc=&exc; excn.prev=curre xc;\
currexc = excn.prev->next = &excn;\
if ( setjmp(excn.buf )==0 )
#define catch(e) \
Exception *e = &exc;\
for (;0;currexc=cur rexc->prev)
#define exctype(et, action) \
if ( e->tp==&et ) { action; }
#define endtry }
#define throw(t,vl) \
{currexc->exc->tp=NULL;\
currexc->exc->tp=&t;\
currexc->exc->val->Char=(char*)vl ;\
currexc->exc->dt=CharType; \
jmp_buf buf;\
memcpy((void*)& buf,(void*)curr exc->buf, sizeof(jmp_buf) );\
longjmp(buf,1); }
ExcType RuntimeError;
int main(int argc, char **argv)
{
try {
throw(RuntimeEr ror,"test error");
} catch(e) {
fprintf(stderr, "caught\n") ;
exit(0);
} endtry
fprintf(stderr, "uncaught\n ");
return 42;
}
--- snap ---
Greetings,
Fabiano This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Zhang |
last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images
from server and display those images.
I created a thread (also a separate toplevel window) for displaying
images and another thread for recording the frame rates (using a
progress bar for visulization). The whole application worked very well
once it received image data from the socket.
The problem is when I tried to close that display window (click on the
standard...
|
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 caller by specifying a throws
clause as well.
is there a similar machanism in c++? i want to force a developer to write
handlers for all possible exceptions a method of my class library can throw.
|
by: Kevin Goodsell |
last post by:
If I'm writing a class that will be used as an exception, what kinds of
things do I need to watch out for? For example, is it necessary to make
sure that the members of the class don't throw?
Suppose my class has one or more std::string members. These could throw
bad_alloc on construction or copy. Is this dangerous? Here's an example:
#include <string>
class SimpleException
|
by: Daniel Wilson |
last post by:
I am having exception-handling and stability problems with .NET. I will
have a block of managed code inside try...catch and will still get a generic
..NET exception box that will tell me which assemblies are loaded before
shutting down. In one case, some of my DB-accessing code didn't handle a
NULL value properly. But try...catch wouldn't catch the exception and keep
going. I'd just get the error message and then it would shut the...
|
by: linq936 |
last post by:
Hi,
I am using gcc3.2.3 on Red Hat Linux. I just find a strange thing of
exception handling:if I compile the code in debug level, then the
exception can be caught; if I compile it in optimized level , then the
exception can not be caught.
The compile option for debug is
-c -DUNIX -fexceptions -g3 -DDEBUG -DLIN
The compile option for optimize is
| |
by: David B |
last post by:
Why is it so difficult to report bugs to Microsoft? I have a documented bug
and an small test example. I don't really see why I should have to pay to
tell them about it...
Anyway, the following code exhibits the bug. If it is built and run from
Visual Studio.NET 2003 in debug mode it works correctly as expected.
However, if built in Release mode it fails with an "uncaught exception"
error, although the exception does have a valid...
|
by: HairlipDog58 |
last post by:
I have a VC++6 project where I need to delay load a DLL. I used a structured
exception handling frame and all seems to work when I build the debug version
and run it (either in or out of the debugger). In debug build, the exception
is caught and reported gracefully to the user. When I build the release
version and run it, the SEH frame does not catch the exception and the
application crashes.
Has anyone had a similar experience and if...
|
by: junw2000 |
last post by:
Is C++ Exception handling useful? think it is too complicated. What
kinds of project need to use it? Thanks.
|
by: joseph_gallagher |
last post by:
Hi,
I've recently ported a .Net 1.1 application to .Net 2.0 and the one new
feature that is getting on my nerves is that when there is an unhandled
exception the application completely crashes, causing user to loose all
the work they have done where they could previously just click continue
and in 99% of cases be fine. Is there an option to turn this annoying
crash and loose everything option off, I can see it has its merits but
in my...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |