🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #568

Question about exception handling

#568
From: Michey Mehta
Date: Tue, 30 Oct 1990 19:44
52 lines
1651 bytes
Hi,

This is a request for clarification about the exception handling
chapter in the ARM.

Consider the following example:

//////////////////////////////////////////////
class base {
public:
   virtual void fixit(){};
};

class derived : base {
public:
   virtual void fixit(){};
};

void func() {
   base* object = new derived;
   throw(*object);
}

main(){
   try {
      func();
   }
   catch(derived obj){
      obj.fixit();
   }
   catch(base obj){
      obj.fixit();
   }
}
//////////////////////////////////////////////

The question is: should derived::fixit be invoked or base::fixit?
The ARM says on page 356 "A throw-expression initializes a temporary
object of the static type of the operand of throw and uses that temporary
to initialize the appropriately-typed variable in the handler". 

1.  Since the ARM says *static type*, can we cut the object back to
being a "base" object?  

2. In that case, should we fall into the "catch (base obj)" ?

3. If so, isn't the vtbl entry for obj still pointing to derived::fixit,
   which could lead to problems?

Michey Mehta
Hewlett-Packard California Language Lab.     Internet: mnm@hpda.hp.com
Phone : (408) 447-5740                           UUCP: ...!hplabs!hpda!mnm
Technical Details
Message-ID: <60060001@hpclove.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!sdd.hp.com!hplabs!hpcc05!hpcuhb!hpcllla!hpclove!mnm

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!sdd.hp.com!hplabs!hpcc05!hpcuhb!hpcllla!hpclove!mnm
From: mnm@hpclove.HP.COM (Michey Mehta)
Newsgroups: comp.std.c++
Subject: Question about exception handling
Message-ID: <60060001@hpclove.HP.COM>
Date: 30 Oct 90 19:44:24 GMT
Organization: Hewlett Packard Calif. Language Lab
Lines: 52