f



A failure to handle exceptions

gcc v3.3.5

  When the exception is thrown "throw error_handler(pmmsend_rc)" the
program aborts (SIGABRT). The constructor completes; the abort occurs
after initialization, presumably in the catch() statement.
  I can see no reason for this unreasonable behavior.
  Am I missing anything? Or should I blame the compiler?


class error_handler {
  private:
    const char * txt;
    pmmsend_return_code_t rc;

  public:
    error_handler (pmmsend_return_code_t err_rc = RC_NO_ACTION) { rc =
err_rc; }
    pmmsend_return_code_t return_code () const { return rc; };

    const char * return_text () {
        switch (rc)
        {
            default:            txt = "Unhandled Error";
            case RC_NO_ERROR:   txt = "No Error";
            case RC_NO_ACTION:  txt = "Nothing happened";
            case RC_HELP:       txt = "Help displayed";
	    // more to come...
         }
        return txt;
     }
};

int main (int argc, char *argv[])
{
    pmmsend_return_code_t pmmsend_rc = RC_NO_ACTION;
    prog_args_t prog_args;

    try {
        if (RC_NO_ERROR !=  pmmsend_rc)
            throw error_handler(pmmsend_rc);

        // build message
        // send message
     }
    catch (const error_handler & ex) {
        cerr << "Error: " << ex.return_code() << endl;
     }
    catch (...) {
        cerr << "Splat! The unhandled error." <<  endl;
     }

    exit(pmmsend_rc);

}



-- 
James Moe
jmm-list at sohnen-moe dot com


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
James
3/27/2016 7:29:31 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

2 Replies
444 Views

Similar Articles

[PageSpeed] 27

On Sunday, 27 March 2016 14:30:15 UTC+2, James Moe  wrote:
> gcc v3.3.5
> 
>   When the exception is thrown "throw error_handler(pmmsend_rc)" the
> program aborts (SIGABRT). The constructor completes; the abort occurs
> after initialization, presumably in the catch() statement.
>   I can see no reason for this unreasonable behavior.
>   Am I missing anything? Or should I blame the compiler?
> 
> 
> class error_handler {
>   private:
>     const char * txt;
>     pmmsend_return_code_t rc;
> 
>   public:
>     error_handler (pmmsend_return_code_t err_rc = RC_NO_ACTION) { rc =
> err_rc; }
>     pmmsend_return_code_t return_code () const { return rc; };
> 
>     const char * return_text () {
>         switch (rc)
>         {
>             default:            txt = "Unhandled Error";
>             case RC_NO_ERROR:   txt = "No Error";
>             case RC_NO_ACTION:  txt = "Nothing happened";
>             case RC_HELP:       txt = "Help displayed";
> 	    // more to come...
>          }
>         return txt;
>      }
> };
> 
> int main (int argc, char *argv[])
> {
>     pmmsend_return_code_t pmmsend_rc = RC_NO_ACTION;
>     prog_args_t prog_args;
> 
>     try {
>         if (RC_NO_ERROR !=  pmmsend_rc)
>             throw error_handler(pmmsend_rc);
> 
>         // build message
>         // send message
>      }
>     catch (const error_handler & ex) {
>         cerr << "Error: " << ex.return_code() << endl;
>      }
>     catch (...) {
>         cerr << "Splat! The unhandled error." <<  endl;
>      }
> 
>     exit(pmmsend_rc);
> 
> }

That is not your complete program.  (You have omitted the definition of
pmmsend_return_code_t at a minimum).  Have you elided anything else? 
If so I suspect that is where your problem lies.  The other potential
problem might be that your constructor never initializes "txt" (but you
never use it either, so that *should* be alright).


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Martin
3/29/2016 7:02:43 AM
* James Moe <jimoeDESPAM@sohnen-moe.com>
| gcc v3.3.5
--<snip-snip>--
|   Am I missing anything? Or should I blame the compiler?

gcc 3.3.5 was released in September 2004, and I doubt it that anyone is
still working or even interested in gcc problems dating back that far.
Better retry using a current compiler version (and provide a compilable
example when you find the same error there).

HTH
R'


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Ralf
3/29/2016 1:38:36 PM
Reply:

Similar Artilces:

Handle C++ exception and structured exception together
Hello everyone, I am learning set_se_translator, and there are some good resources about how to translate structured exception into C++ exception, like, http://www.codeproject.com/KB/cpp/seexception.aspx 1. What makes me confused is, when we are talking about translate, it means both structured exception and C++ exception may occur in a C++ program, right? 2. But from build option, we can select either /EHa or /EHsc, means we can only select one type of exception, either asynchronous (structured) or synchronous (C++ exception). (1) and (2) are conflict? thanks in advance, George Geo...

Question about mixing c++ exception handling & c code
Hi, I was looking thru code in my organisation. same dll is sharingcode is mixing c++ code & c code, which is being again called by some other c+ + dll. Only issue I am not too sure about exception handling in this case - here is trimmed code snippet - include.h typedef void (func*)(void *,bool); struct scriptparams { func callback; void *obj; }; test.cpp class execption { public: virtual void printerror(){//do something}; }; class foo { public: foo(){}; void dosomething(bool arg) { cout>>"do something">>endl; if(!arg) throw execption; //if valid do someth...

C++ Exception Handling
Hi all, Does anyone know of an implementation of: ___CxxFrameHandler __CxxThrowException __EH_prolog for use in an NT\W2K\XP Driver environment? Or does anyone know where I can get the source code for these so that I could look at doing an implementation? I don't want to get into the whole 'C versus C++' argument, I was just wondering if anyone could help out :-) TIA Don't use them, use SEH instead. -- Don Burn (MVP, Windows DDK) Windows 2k/XP/2k3 Filesystem and Driver Consulting Remove StopSpam from the email to reply "P...

Exceptions in C/C++
Hello, I have question concerning such code: __try { ... } __except(EXCEPTION_EXECUTE_HANDLER) { printf("Exception code: %.8x\n", GetExceptionCode()); } Is C related code? Or maybe C++? opexoc opexoc@gmail.com wrote: > Hello, > > I have question concerning such code: > > __try > { > ... > } __except(EXCEPTION_EXECUTE_HANDLER) > { > printf("Exception code: %.8x\n", GetExceptionCode()); > } > > > Is C related code? Or maybe C++? It's not ISO C, but Microsoft specific C, see their MSDN doc. -- Tor <b...

How C++ Exception handling works ?
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 resides across DLL boundary (i.e. The Catch block is there in another DLL). In that case the compiler can not put the code for jumping to the catch point. What I think is that there needs to be some explicit support from the OS that would maintain the try/catch block in the kernel context and the compiler will get the jump context from the OS. In that case a C++ compiler (Supporting exception handling) c...

Exceptions handling in pure C
How can translate C++ to C code with exceptions handling? Unfortunately Stroustrup translator cfron has only source and not compiled, llvm command to translate C++ => C not works. Borneq wrote: > How can translate C++ to C code with exceptions handling? Unfortunately > Stroustrup translator cfron has only source and not compiled, llvm command > to translate C++ => C not works. Two options: Start from scratch. Use Comeau http://www.comeaucomputing.com/ -- Ian Collins Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości news:aidkuhFac77U1@mid.individual.net... > Start from scratch. How start? I haven't information about exception handling in C > Use Comeau http://www.comeaucomputing.com/ Online http://www.comeaucomputing.com/tryitout/ can translate to C or only to assembler? Borneq wrote: > Użytkownik "Ian Collins" <ian-news@hotmail.com> napisał w wiadomości > news:aidkuhFac77U1@mid.individual.net... >> Start from scratch. > > How start? I haven't information about exception handling in C There isn't any, you have to rewrite the code from scratch. >> Use Comeau http://www.comeaucomputing.com/ > > Online http://www.comeaucomputing.com/tryitout/ can translate to C or only > to assembler? Neither. You have to buy the compiler. -- Ian Collins On 12/7/2012 2:41 AM, Ian Collins wrote: > Borneq wrote...

C++: rethrow in exception handling
Hi, I'm having some difficulty understanding the semantics of the rethrow keyword. Consider the following code: int main(){ try{ ... } catch(SomeException &SE){ ... } catch(...){ rethrow; } return 0; } What is the point of rethrowing the exception caught at catch(...)? Won't this result in a endless cycle effect? Regards, A A wrote: > Hi, > hi > What is the point of rethrowing the exception caught at catch(...)? Won't > this result in a endless cycle effect? > no. you can use it to do some cleaning before lettin...

converting c++ exception handling into SEH
ello, i have a problem with replacing c++ exception handling with structured exception handling. How to replace the " catch(...) " in c++ exception handling with, __except , a structured exception handling. If i write "#define catch(...) ----" ; then it doesn't take ' ... ' as a string ; so, prompts an error.. error C2010: '.' : unexpected in macro formal parameter list what to be written in place of ' --- ' ; to be convert it into an St.Ex.Handling.? yogesh wrote: > ello, i have a problem with replacing c++ exception handlin...

C++ Exception handling in Tornado2.2
Hi, I am working on an application with uses c++ compiler provided by Tornado ( Gcc version 2.96). The application uses c++ exception handling features. Now, Is it safe to use c++ exception handling features int a multithreaded enovironmmnet ?... (I know that some versions of gcc's exception handling feature does not work properly in multithreaded environment) Has anybody tried this before? ANY HELP?? Regards Pavan pavana.murthy@gmail.com wrote: > Hi, > I am working on an application with uses c++ compiler provided > by Torn...

Exception Handling (C
Hi all, Where does PyExc_TypeError (and alike) points to? I can see its declaration - PyAPI_DATA(PyObject *) PyExc_TypeError; - in pyerrors.h but I cannot figure out what it is its value, where it is initialized. Any help is greatly appreciated. Lee Lee, 23.10.2011 06:09: > Where does PyExc_TypeError (and alike) points to? I can see its > declaration - PyAPI_DATA(PyObject *) PyExc_TypeError; - in pyerrors.h > but I cannot figure out what it is its value, where it is > initialized. It gets initialised inside of the interpreter core and then points to a Python object. > An...

Typical C++ Exception Handling implementations
Can someone share some ways that current compilers deal with the C++ exception handling mechanism? I'm especially curious about the overheads associated with the various techniques. In particular, I'd like to know: - Ways to track which automatic objects have been constructed and need to be destructed, and in which order - If static-analysis methods exist, and what the relative overheads are of such techniques versus run-time stack-bound methods - Where the exception object is stored, and when it is constructed and destructed - Ways to match the exception object type against the catch...

Ruby exception handling while we embedded in C++
Hi I have embedded Ruby in C++ application and want to handle Ruby exception in C++ application. Please let me know any good reference documents for Ruby exception handling while we embedded in C++. Regards Chirag -- Posted via http://www.ruby-forum.com/. ...

converting c++ exception handling into SEH
Hello, i have a problem with replacing c++ exception handling with structured exception handling. How to replace the " catch(...) " in c++ exception handling with, __except , a structured exception handling. If i write "#define catch(...) ----" ; then it doesn't take ' ... ' as a string ; so, prompts an error.. error C2010: '.' : unexpected in macro formal parameter list what to be written in place of ' --- ' ; to be convert it into an St.Ex.Handling.? ...

Basic question on exception handling in C++
In all the sample code snippets of try-catch code blocks that I have seen, the catch block does one of the following three things: 1). exits the program (after spitting out a cerr message) 2). propagates the exception 3). throws yet another exception I have a need to do something different. I want to merely spit out a cerr message when I catch an exception, and then proceed with my business logic. I am thinking of something like this: ////// Code snippet begin ///// bool noException = true; try { // some business logic operation } catch(std::exception& xcptn) { noException = f...

Exception handling in Visual C++ 2003
I'm using VC++ 2003. My code throws lots of exceptions but the debugger's handling of these makes the program (and hence debugging process) unusably slow; this was not the case in VC++ 6. So my questions are: 1) is it possible to disable the exception interception mechanism so that the debugger is usable (note that the exception handling to continue with the Exceptions dialogue does not do this) 2) has this problem been fixed in 2005 so that the debugger is usable with code that throws lots of exceptions TIA Simon Geard * simon@whiteowl.co.uk: > I'm using VC++ 2003. My c...

C++ exception and OS exceptions
As we know some exceptions, such as floating point exception and division by zero, can not be caught by the standard C++ exception handling mechanism. They are undefined behaviors according to the current C++ standard. This is quite reasonable since we do not have a standardized platform at all. However, we can not live without an underlying OS, therefore for real world applications we need to handle the OS exceptions. The problem is how to do it in a systematical manner. 1. Can we catch the C++ exceptions and OS exception together? I think the answer is possibly yes. but ... 2. How ca...

Need help on how to handle C level exceptions
We are loading multiple tcl sessions into a java environment using TclBle= nd.=20 When an exception occurs in TCL we need to ensure this doesn=92t cause th= e=20 Java process to exit but allows us to handle the cleanup and removal of t= he=20 interpreter in a controlled and known manner. To attempt to do this, We d= id=20 the following: 1) Redefine the TCL Panic handler to prevent the abort function= =20 from being called and throw an exception (windows only). 2) Modify the JNI wrapper to catch the exception. 3) Construct a suitable error message to...

Simulate C++ Exception handling with setjmp/longjmp?
Hi, I have searched with Google, but only find some simple example of this. Could anybody tell me is there any library or complete code used for simulating all the Exception of OO language? Thanks! Regards! Bo Bo Yang wrote: > Hi, > I have searched with Google, but only find some simple example of > this. Could anybody tell me is there any library or complete code used > for simulating all the Exception of OO language? Thanks! Many people have done it, many times. The broad outline is always the same (`throw' is a longjmp(), `catch' is a setjmp()), but the de...

How to use C++ exception handling and RTTI in drivers
Hello, from time to time it is discused how to use C++ exception handling and RTTI in drivers, for example Gary Nebbett described how to extract the needed part of Microsofts normal runtime library and link the driver with it. His post can be read at: http://groups.google.com/groups?selm=3976f1b3%40guardhouse.chbs Another method is to reimplement the runtime suport for C++ exceptions and RTTI, I have managed to do that and made it available at: http://www.acc.umu.se/~bosse/libcpp2.zip There are not realy any advance of using this method over the former one if you just need to use C...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta > * open source - preferable, but not 100% necessary what's wrong with using C? Friedrich > what's wrong with using C? Too low level, no built-in garbage collection. -- Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: >> what's wrong with using C? > > Too low level, Well the Smalltalk people say, have a small language and a big library. I assume C's library status beyond that of Smalltalk. > no built-in garbage collection. Use the Boehm Weisser GC. Friedrich "Kevin Albrecht" <kevin@albrecht.net> wrote in message news:<2TiYb.237892$rj7.1641209@twister.tampabay.rr.com>... > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) > ...

[ace-users] C++ Exception handling model for Win32 builds
I see that recent (e.g. ACE 5.5 and ACE 5.6) Win32 builds of ACE are compiled with the compiler option /EHa ("asynchronous exception handling"). I was wondering whether it's worth considering changing this to /EHsc ("synchronous exception handling"). To briefly recap the difference between these exception handling models, asynchronous exception handling essentially means two things: a) The compiler must assume that any line of code could throw. This prevents some optimizations. b) catch (...) catches OS-level faults (e.g. access violations). By contrast, synchronous exception handling means that the compiler can assume that only function calls or explicit throws throw an exception, and catch(...) will only catches C++ exceptions. As I understand, ACE deliberately decided to use asynchronous exception handling. In particular, I saw this entry in the ace changelog: Tue Dec 6 18:40:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> * bin/MakeProjectCreator/config/acedefaults.mpb: For vc8 set ExceptionHandling to 2. This enabled the structured exception handling. Normally vc8 doesn't catch structured exceptions but we except so for some tests and else the disabling of the win32 error windows doesn't work. This fixes bugzilla [BUG:2290] See also http://www.codecomments.com/archive292-2005-8-578262.html for backgroup. Thanks to Steve Huston and Chad Elliott for proposing to...

Re: [ace-users] C++ Exception handling model for Win32 builds #2
Johnny Willemsen said: > I did remember disabling the error window didn't work with /Eha. The issue > is that I don't have free time to retest this at this moment. I can only do > that as part of our commercial services. Can you file this in bugzilla (see > http://deuce.doc.wustl.edu/bugzilla/index.cgi). Done. It's Bug 3169. Out of interest, what do you need to test? I've written a little non-ACE program and verified that a unhandled exception filter is called with /EHsc. I've also recompiled ACE with ACE_DISABLE_WIN32_ERROR_WINDOWS, introduced an access violation to one of the regressions tests and verified that it don't show the error window when that option is set. Is there anything else I can do to help? > > > As a minor improvement, if we really do want to prevent win32 error > > dialogs from appearing, we may want to consider calling > > SetErrorMode(SEM_FAILCRITICALERRORS) in the code in the #ifdef > > ACE_DISABLE_WIN32_ERROR_WINDOWS block. > > Can you add this also to bugzilla It's in as Bug 3170 Adrian ...

signal handling and (structured) exception handling
I'm a little bit at loss, why the new C++ standard (C++0x) does not include something like Windows structured exception handling. I certainly prefer a C++ Exception to a signal, as the signal only gives you the choice to terminate the process or mess around with something as ugly as setjmp/longjmp. And such signals/exceptions can sometimes not be avoided, e.g. in case of the system runs out of disk space while writing into memory created by memory mapped io from a sparse file. Even in case of a null pointer access I would prefer to keep the application running to be able to terminate it c...

Web resources about - A failure to handle exceptions - comp.lang.c++.moderated

GPL linking exception - Wikipedia, the free encyclopedia
A GPL linking exception modifies the GNU General Public License (GPL) to create a new, modified license. Such modified licenses enable software ...

Podcast #42 – It’s The Exception That Proves The Rule
... Language and Usage , which was frustrated by the high number of certain types of questions that were coming in. Is this podcast the exception ...

Alan Adler on WIPO negotiations on copyright exceptions - YouTube
Alan Adler is Vice President for Legal and Government Affairs for the Association of American Publishers. On July 18, 2012, Alan was interviewed ...

Queensland the exception as Labor to preference Greens before all in Senate
Labor's national executive has ordered the party to preference the Greens ahead of all others in every state except Queensland.

Bike thefts spike in exception to drop in crime
Bicycle thefts in Canberra soar to highest level in nine years, with a 28 per cent jump in three months.

Many rugby films wind up in dead ball area but The Ground We Won is an exception
If rugby is the game they play in heaven, rugby movies generally come from a lesser place.

Remakes are all the rage, and sport's no exception
Over the past year or so, franchises such as Star Wars and Rocky have solidified what many pundits already believed, and that is that people ...

Is Richard Umbers, Bernie Brookes' replacement as Myer CEO, an exception?
Myer's CIO was recently elevated to the top job, but he's in a very small minority.

Men Need to Admit That Jian Ghomeshi Is No Exception
That men like Jian Ghomeshi are a terrible exception and if we as men simply stand up and say we are not as bad as that, or that we are not rapists ...

China, Thailand reach visa exception agreement
China, Thailand reach visa exception agreement People's Daily Online ... this at a forum on China's foreign diplomacy held in Beijing. Both ...

Resources last updated: 3/27/2016 12:30:49 PM