|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - How to catch runtime errors of the C++ standard library with DigitalMars
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/
Jan 21 2004
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: Jan 21 2004
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/
Jan 21 2004
Rolf Hemmerling wrote:Hello ! This missing feature is a feature of the standard library! So the STL **Template** library does not help. Jan 21 2004
Rolf Hemmerling wrote:Hello ! This missing feature is a feature of the standard library! So the STL **Template** library does not help. Jan 21 2004
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/
Jan 22 2004
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/
Jan 22 2004
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/
Jan 22 2004
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 Jan 22 2004
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/
Jan 22 2004
Rolf Hemmerling wrote: Jan 22 2004
Hello ! Jan Knepper wrote: Jan 23 2004
Rolf Hemmerling wrote: Jan 22 2004
"Rolf Hemmerling" <hemmerling gmx.net> wrote in message news:bulkfe$501$1 digitaldaemon.com...Hello ! How to catch runtime errors with DigitalMars C++ ? Jan 26 2004
|