Thread overview | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 21, 2004 How to catch runtime errors of the C++ standard library with DigitalMars C++ ? | ||||
---|---|---|---|---|
| ||||
Hello ! How to catch runtime errors with DigitalMars C++ ? There is no #include <stdexcept> and nothing similar, but just #include <eh.h> The problem is "Error: undefined identifier 'runtime_error' catch( runtime_error e)" So the exceptions usually defined in <stdexcept> are not defined for this compiler at all ?! Is this a lack of feature ? Any workaround to work with standard runtime exceptions ? See this german example, if you allocate "1000" MBytes, the runtime error should be catched, by standard exceptions. Of course I MIGHT throw a user-defined exception. But if there are no system exceptions with DMC, means that I cannot use portable code for other compilers which depend on this feature ! So I must know for my own development. Btw, some other C++ exception features like set_terminate() and set_unexpected() are just defined in #include <eh.h> , not in #include <exception> :-( Any reason for that ? Sincerely Rolf // 6. Beispiel Fehlerbehandlung / Exceptionhandling // - vorgegebene Exceptions aus der C++-Standardbibliothek // definiert in <stdexept> // Klassenhierarchie: // exception <--- bad_cast // bad_alloc // bad_exception // bad_typeid <--- __non_rtti_object // logic_error <--- domain_error // invalid_argument // length_error // out_of_range // runtime_error <---- overflow_error // range_error // underflow_error #include <iostream> #include <stdexcept> using namespace std; int main() { char *buffer; int mb; // Zu überwachender Block try { cout << "Wieviel MB soll reserviert werden? "; cin >> mb; buffer = new char[1024*1024*mb]; if (buffer==NULL) throw runtime_error("Geht nicht"); cout << "Programm läuft weiter ..." << endl; } // Fehlerbehandlungsroutinen catch(runtimeerror e) { cout << "Exception: " << e.what() << endl; return 1; } cout << "Programm fehlerfrei beendet." << endl; return 0; } -- / / / Alone on the data highway... / / like on an allee in Hannover-Herrenhausen / / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany / / / http://www.hemmerling.com/ |
January 21, 2004 Re: How to catch runtime errors of the C++ standard library with DigitalMars C++ ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | Most of DMC++'s "Standard C++ compliance" comes from the STLport package. If you add "-I\dm\stlport\stlport" to your compile command line, your problems should be solved.
Note: change "\dm" to the top directory where you installed DMC.
-scooter
Rolf Hemmerling wrote:
> Hello !
>
> How to catch runtime errors with DigitalMars C++ ?
> There is no
> #include <stdexcept>
> and nothing similar, but just
> #include <eh.h>
>
> The problem is
> "Error: undefined identifier 'runtime_error' catch( runtime_error e)"
>
> So the exceptions usually defined in <stdexcept> are not defined for this compiler at all ?!
>
> Is this a lack of feature ? Any workaround to work with standard runtime exceptions ?
>
> See this german example,
> if you allocate "1000" MBytes, the runtime error should be catched, by
> standard exceptions.
>
> Of course I MIGHT throw a user-defined exception.
>
> But if there are no system exceptions with DMC, means that I cannot use portable code for other compilers which depend on this feature ! So I must know for my own development.
>
> Btw, some other C++ exception features like
>
> set_terminate()
> and
> set_unexpected()
>
> are just defined in
> #include <eh.h>
> , not in
> #include <exception>
> :-(
> Any reason for that ?
>
> Sincerely
> Rolf
>
> // 6. Beispiel Fehlerbehandlung / Exceptionhandling
> // - vorgegebene Exceptions aus der C++-Standardbibliothek
> // definiert in <stdexept>
> // Klassenhierarchie:
> // exception <--- bad_cast
> // bad_alloc
> // bad_exception
> // bad_typeid <--- __non_rtti_object
> // logic_error <--- domain_error
> // invalid_argument
> // length_error
> // out_of_range
> // runtime_error <---- overflow_error
> // range_error
> // underflow_error
>
> #include <iostream>
> #include <stdexcept>
> using namespace std;
>
> int main()
> {
> char *buffer;
> int mb;
>
> // Zu überwachender Block
> try
> {
> cout << "Wieviel MB soll reserviert werden? ";
> cin >> mb;
> buffer = new char[1024*1024*mb];
> if (buffer==NULL)
> throw runtime_error("Geht nicht");
> cout << "Programm läuft weiter ..." << endl;
> }
>
> // Fehlerbehandlungsroutinen
> catch(runtimeerror e)
> {
> cout << "Exception: " << e.what() << endl;
> return 1;
> }
> cout << "Programm fehlerfrei beendet." << endl;
> return 0;
> }
|
January 21, 2004 Re: How to catch runtime errors of the C++ standard library with DigitalMars C++ ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Scott Michel | Hello !
This missing feature is a feature of the standard library!
So the STL **Template** library does not help.
I just found out that other "old" compilers lack of the feature, too., like "Microsoft VC++ 4.0" ( which has basic support for exceptions, in opposite yet older 16-bit versions ).
In opposite, OpenWatcom and BCC 5.5 support the feature.
Any other suggestions ?
Sincerely
Rolf
--
/ / / Alone on the data highway...
/ / like on an allee in Hannover-Herrenhausen
/ / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany
/ / / http://www.hemmerling.com/
|
January 21, 2004 Re: How to catch runtime errors of the C++ standard library with DigitalMars C++ ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | Rolf Hemmerling wrote: > Hello ! > > This missing feature is a feature of the standard library! > So the STL **Template** library does not help. I think STLport is quite a bit more than just STL.. www.stlport.org -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org |
January 22, 2004 Re: How to catch runtime errors of the C++ standard library with DigitalMars C++ ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | Rolf Hemmerling wrote:
> Hello !
>
> This missing feature is a feature of the standard library! So the STL **Template** library does not help.
The STLport is a ***LOT*** more than just STL templates. The STLport library has a lot of "extra" headers that help the compiler environment conform to standard C++.
The current DMC++ design relies on STLport to provide this additional layer of conformity, rather than reinvent the compiler's header files to achieve conformity. I could be wrong, but that's my impression based on compiling my code that relies on standard C++ iostream.
-scooter
|
January 22, 2004 No success with STLport + "set_terminate" + "runtime_error" | ||||
---|---|---|---|---|
| ||||
Posted in reply to Scott Michel | Hello ! I found out "set_terminate()" is mentioned in the file dm/stlport/stlport/exception and "runtime_error" is mentioned in the file (installpath)dm/stlport/stlport/stdexecpt but if I try to compile with "(installpath)dm\stlport\stlport", I still get the error messages that the compiler does not find "set_terminate()" and "runtime_error" ! Any suggestions ? Sincerely Rolf -- / / / Alone on the data highway... / / like on an allee in Hannover-Herrenhausen / / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany / / / http://www.hemmerling.com/ |
January 22, 2004 No success with STLport + "set_terminate" + "runtime_error" (2) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | Hello ! I wanted to say, that including #include <stdexcept> #include <exception> did not help, although these are "the" exception header files for STLport !! :-(. Sincerely Rolf -- / / / Alone on the data highway... / / like on an allee in Hannover-Herrenhausen / / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany / / / http://www.hemmerling.com/ |
January 22, 2004 Re: No success with STLport + "set_terminate" + "runtime_error" (2) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | MOre clearly: I used the example from the tread start and added #include <stdexcept> #include <exception> in the file, while I put the directory of STLPORT at the first position of the include path string, and the compiler even did not find set_terminate() runtime_error :-( So what's wrong with me ? Must I use special namespaces for use with STL ?? Please help, if you can! I am a newbie to C++, btw ( but with some C and some Java experience ). Sincerely Rolf -- / / / Alone on the data highway... / / like on an allee in Hannover-Herrenhausen / / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany / / / http://www.hemmerling.com/ |
January 22, 2004 Re: No success with STLport + "set_terminate" + "runtime_error" (2) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rolf Hemmerling | Can you post the message? I wonder whether it is the compiler or the linker that can not find the stuff you mention. Rolf Hemmerling wrote: > MOre clearly: > > I used the example from the tread start and added > #include <stdexcept> > #include <exception> > > in the file, > while I put the directory of STLPORT at the first position of the include path string, and the compiler even did not find > > set_terminate() > runtime_error > > :-( > > So what's wrong with me ? > > Must I use special namespaces for use with STL ?? > > Please help, if you can! > I am a newbie to C++, btw ( but with some C and some Java experience ). > > Sincerely > Rolf -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org |
January 22, 2004 No success with STLport + "set_terminate" + "runtime_error" (3) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | Hello ! At first, my starting-C++ project is a multi-compiler project. So with the "same" very-complicated makefile and a common header file, I succeeded with OTHER compilers to include those header files which contain the definitions for "set_terminate()" and "runtime_errror". For example, with OpenWatcom, this ***** class _WPRTLINK runtime_error : public exception { public: runtime_error( string const& what_arg ) _WCTHROWS(()) : exception( what_arg ) { } }; **** defines the "runtime_error" in the proper header files, which I did not find with MingW, MS VC++4.0 and DMC ! So if I include #include <stdexcept> #include <exception> , these files ARE found by the compiler, nethertheless they don´t contain the proper information to support "set_terminate()" and "runtime_error" ( as I said, this is **standard library stuff", as the actions of the standard libarary operations are controlled by try..catch with "runtime_error" ect. here are the error messages: ********************* set_terminate( exitus ); ^ ..\..\src\data\exception\Exception.cpp(153) : Error: undefined identifier 'set_terminate' set_unexpected( wasIstLos ); ^ ..\..\src\data\exception\Exception.cpp(217) : Error: undefined identifier 'set_unexpected' throw runtime_error ("Geht nicht"); ********************* So if I setup the right include path, the include files are found, but are not sufficent. So I think that the STLlib does NOT help with "set_terminate()" and "runtime_error" :-(. Support for "set_terminate()" is by #include <eh.h> of the standard non-STL include files, , but there is no support for "runtime_error" ? :-(. Any suggestions ? Sincerely Rolf -- / / / Alone on the data highway... / / like on an allee in Hannover-Herrenhausen / / / The Hemmerling (R) WEB site - Rolf Hemmerling,Germany / / / http://www.hemmerling.com/ |
Copyright © 1999-2021 by the D Language Foundation