🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Waye-Ian CHIEW Fri, 06 Dec 1996 00:00
Exception handling
#6131
Author: Waye-Ian CHIEW
Date: Fri, 06 Dec 1996 00:00
23 lines
902 bytes
Hello!



   class General { };
   class Specific : public General { };

   int main () {
      try { 
	 throw New Specific;
      }

      catch ( General* general ) { }
   }

  
This falls though without catching and aborts.  Why doesn't gcc match the Specific object to General?



-- Ian!!
ASM programmers drive stick shifts.
Re: Exception handling
#6133
Author: Alex Martelli
Date: Fri, 06 Dec 1996 00:00
33 lines
1721 bytes
wchi@students.cs.mu.oz.au (Waye-Ian CHIEW) writes:

>   class General { };
>   class Specific : public General { };

>   int main () {
>      try { 
>	 throw New Specific;
>      }

>      catch ( General* general ) { }
>   }

>  
>This falls though without catching and aborts.  Why doesn't gcc match the Specific object to General?

As a guess, I would point out the fact that the General and Specific
classes are not polymorphic; by the ANSI C++ draft standard, a compiler
only has to do runtime type identification (surely in dynamic_cast<>,
but I believe in try/throw/catch too) for objects of classes that are
polymorphic (i.e., have at least one virtual function).  This is to
avoid mandating rtti's overhead on every object.  Try adding a virtual
function in General and see if that works as you expect (I don't have
a gcc with working exception handling so I can't test that myself).


Alex
--
DISCLAIMER: these are MY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it -- Phone: +39 (51) 597 313  [Fax: 597 120]
Cad.Lab S.p.A., v. Ronzani 7/29, 40033 Casalecchio (BO), Italia
Re: Exception handling
#6136
Author: Andreas Schwab
Date: Fri, 06 Dec 1996 00:00
22 lines
1186 bytes
Waye-Ian CHIEW <wchi@students.cs.mu.oz.au> writes:

|> Hello!
|>    class General { };
|>    class Specific : public General { };

|>    int main () {
|>       try { 
|> 	 throw New Specific;
|>       }

|>       catch ( General* general ) { }
|>    }

  
|> This falls though without catching and aborts.  Why doesn't gcc match the Specific object to General?

Without -frtti gcc only supports exact matches for catched objects.
-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads