Programmieren - alles kontrollieren 4.935 Themen, 20.621 Beiträge

Linux/gcc 3.2.3/C++: new mit nothrow. Wie?

d-oli / 5 Antworten / Flachansicht Nickles

Hi


 


Ich habe da ein Programm das von UNIX auf Linux portiert wurde. In diesem Programm hat es unter anderem ein Error-Fenster das erzeugt wird wenn ein Speicherfehler vorliegt. Das Ganze sieht ungefähr so aus:


 


class guiErrorMsg : public …


{


public:


&nbsp&nbsp&nbsp guiErrorMsg ( widget TheParent, char* TheMessage, TheTitle );


&nbsp&nbsp&nbsp // etc.


 


private:


&nbsp&nbsp&nbsp // etc.

 


};


 


in main()


{


&nbsp&nbsp&nbsp // etc.


&nbsp&nbsp&nbsp if( new guiErrorMsg( …, …, … ) == NULL )


&nbsp&nbsp&nbsp {


&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp throw( … );


&nbsp&nbsp&nbsp }


&nbsp&nbsp&nbsp // etc.


&nbsp&nbsp&nbsp return 0;


}


 


Ich möchte nun aber, dass kein throw() sondern ein Eintrag in einem Logger ausgeführt wird. Nun habe ich folgendes in einem Fachbuch gelesen:


 


According to the C++ standard, if new runs put of memory, it throws an exception that normally aborts the program. On older C++ systems, when new runs out of memory, it returns a null pointer.


 


Und folgendes habe ich mit $man g++ herausgefunden:


 


<b>-fcheck-new</b>


&nbsp&nbsp&nbsp Check that the pointer returned by "operator new" is non-null


&nbsp&nbsp&nbsp before attempting to modify the storage allocated. The current


&nbsp&nbsp&nbsp Working Paper requires that "operator new" never return a null


&nbsp&nbsp&nbsp pointer, so this check is normally unnecessary.


 


&nbsp&nbsp&nbsp An alternative to using this option is to specify that your "opera-


&nbsp&nbsp&nbsp tor new" does not throw any exceptions; if you declare it tthhrrooww(()),


&nbsp&nbsp&nbsp G++ will check the return value.  See also new (nothrow).


 


Also nehme ich an, dass in meinem Fall ein throw() ausgeführt und nicht ein Null-Pointer zurückgegeben wird.


Aber gerade throw() will ich unterdrücken. Ich kann leider nirgends ein Manual oder ein Beispiel finden (auch mit google nicht) das „See also new (nothrow)“ näher beschreiben würde.


 


Wer kann mir weiterhelfen?


 


Dank und Gruss,


d-oli


 


 
Konstruktive Kritik zeichnet sich dadurch aus, dass sie höflich, nützlich und sachlich ist.
bei Antwort benachrichtigen
Sorry. Noch ein mal. d-oli
Sorry. Noch ein mal. marco72
Enrico_Horn d-oli „Linux/gcc 3.2.3/C++: new mit nothrow. Wie?“
Optionen

Warum machst du das new() nicht einfach innerhalb eines try()...catch()-Statments?

bei Antwort benachrichtigen
TEST westberlin1