log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- RISCOSbits releases a new laptop solution (News:4)
- Announcing the TIB 2024 Advent Calendar (News:2)
- RISC OS London Show Report 2024 (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: GCC and exception troubles
 
  GCC and exception troubles
  Dahman (06:26 23/10/2003)
  Paolo Zaino (17:38 18/3/2004)
    ksattic (05:17 19/3/2004)
  pnaulls (08:56 19/3/2004)
 
Madani Message #47440, posted by Dahman at 06:26, 23/10/2003
Member
Posts: 1
I had all sort of problems with exceptions, using 32 bit GCC 2.9.54 release 3.
Here is the simplest one:

class my_class
{
public:
my_class() {throw "error";}
~my_class() {}

};
------------------------------------------------
int main()
{
try
{
my_class *c = new my_class;
}
catch(const char *message)
{
cout << "message: " << message << endl;
}
catch(...)
{
cout << "uncaught: " << endl;
}
return 0;
}
--------------------------------------------------
int main()
{
my_class *c = 0;
try
{
c = new my_class;
}
catch(const char *message)
{
cout << "message: " << message << endl;
}
catch(...)
{
cout << "uncaught: " << endl;
}
return 0;
}
--------------------------------------------------
The first main() function work fine.
The second one crash the system with this messages:

pc: 167c0 sp: 647f8c post_signal()
pc: 16aec sp: 647fa4 __unixlib_raise_signal()
pc: 3be3c sp: 646b68 __h_cback()
pc: 2003c sp: 646f64 ?()
pc: 23a1c sp: 646f78 _main()

Termination signal received: Segmentation fault

any help please.
  ^[ Log in to reply ]
 
Paolo Fabio Zaino Message #53136, posted by Paolo Zaino at 17:38, 18/3/2004, in reply to message #47440
Member
Posts: 61
Hello Madani,
The problem on the second routine is that you try to assign 0 (Zero) to a Class when you should costruct it.
The First routine works fine because you call the class costructor (using New)
Other then this you should see that the wrong code line is out of the TRY so this exception is not managed by your program and this cause the crash.
Just a trip... when you get a "segmentation fault" error usually it is because you called a pointer and/or a costructor in a bad way (like you did).
Cheers, Paolo.
________
RISC OS Projects: https://github.com/RISC-OS-Community
RISC OS Blog: https://paolozaino.wordpress.com/category/risc-os/
Cheers!
  ^[ Log in to reply ]
 
Simon Wilson Message #53151, posted by ksattic at 05:17, 19/3/2004, in reply to message #53136
ksattic
Finally, an avatar!

Posts: 1291
Both work fine with Visual C++ - I've not tried gcc.

I would recommend writing:
c = new my_class();

instead of:
c = new my_class;

It is also perfectly OK to write:
my_class *c = 0;

But I would recommend using NULL, which is defined as zero anyway.

Finally, I would not recommend declaring a variable or object inside a try block, as it will go out of scope at the end of the block (unless this is what you really want to do).
  ^[ Log in to reply ]
 
Peter Naulls Message #53157, posted by pnaulls at 08:56, 19/3/2004, in reply to message #47440
Member
Posts: 317
I had all sort of problems with exceptions, using 32 bit GCC 2.9.54 release 3.
Here is the simplest one:


The first main() function work fine.
The second one crash the system with this messages:

pc: 167c0 sp: 647f8c post_signal()
pc: 16aec sp: 647fa4 __unixlib_raise_signal()
pc: 3be3c sp: 646b68 __h_cback()
pc: 2003c sp: 646f64 ?()
pc: 23a1c sp: 646f78 _main()

Termination signal received: Segmentation fault

any help please.
Firstly, you should address such problems to the GCCSDK mailing list - no one here is able to fix it. Secondly, this was recently addressed.
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: GCC and exception troubles