🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #826

Re: G++ and exceptions.

#826
From: Joseph H. Kim
Date: Tue, 21 Nov 1995 05:09
75 lines
2695 bytes
In article <199511210138.RAA20958@cygnus.com>, mrs@cygnus.com (Mike Stump)
wrote:

> > From: Kamil Iskra <iskra@student.uci.agh.edu.pl>
> > I just wanted to ask if exceptions in 2.7.1 work well on m68k?
> 
> I don't know.  You can ask in the g++ help group, maybe someone else
> has tried it.  If they don't work, it should be reasonably easy for
> someone to get them working.  The compiler just needs a #define
> RETURN_ADDR_RTX macro defined properly in config/m68k/m68k.h.

Preliminary answer seems to be "yes."

I just got through building gcc/libg++ 2.7.1 on my m68k system,
incorporating the repo patch for good measure.  Below is a quick simple
example code I tried just now:

g++ -v -fhandle-exceptions -O2 test.cpp
(-O3 caused linker to complain of a lot of undefined local "L" symbols...)

************************ 
#include <iostream.h>

class Exception {
public:
  Exception() {};
  virtual void Show(void) { cerr << "Exception" << endl; }
  virtual void Raise(void) const { throw Exception(); };
};

class DerivedException : public Exception {
public:
  DerivedException() : Exception() {};
  virtual void Show(void) { cerr << "DerivedException" << endl; }
  virtual void Raise(void) const { throw DerivedException(); }
};

inline void Assert(const bool pAssertion,
  const Exception& pException) {
  if (pAssertion != true) pException.Raise();
}

int main() {
  for (int i = 0; i < 2; i++) {
    try {
      if (i == 0) Assert(false, DerivedException());
      if (i == 1) Assert(false, Exception());
    } catch (DerivedException& pX) {
      pX.Show();
    } catch (Exception& pX) {
      pX.Show();
    } catch (...) {
      cerr << "UNEXPECTED" << endl;
    }
  }
  return 0;
}

Output (as expected):

DerivedException
Exception

************************ 

I was in the process of incorporating exception handling in my project
until a recent distraction.  I'll rebuild some of my stuff with 2.7.1
pretty soon, so I'll know more then.

Joe
-- 
//===================================================================
//             Joseph H. Kim (joehkim@cs.utexas.edu)
// Recent victim of corporate "Restructuring". Will "OO"-fy for cash.
//            http://www.cs.utexas.edu/users/joehkim/
Technical Details
Message-ID: <joehkim-2011952306470001@localhost>
Path: arc1-ca.pugleaf.net!geraldo.cc.utexas.edu!localhost!user
References: <199511210138.RAA20958@cygnus.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!geraldo.cc.utexas.edu!localhost!user
From: joehkim@cs.utexas.edu (Joseph H. Kim)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: Re: G++ and exceptions.
Date: 21 Nov 1995 05:09:59 GMT
Organization: The University of Texas at Austin
Distribution: world
Message-ID: <joehkim-2011952306470001@localhost>
References: <199511210138.RAA20958@cygnus.com>
NNTP-Posting-Host: slip-33-5.ots.utexas.edu