Welcome, Guest. Please login or register.

Author Topic: Exception troubles!  (Read 12937 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Exception troubles!
« on: December 12, 2002, 10:45:11 AM »
Hi all,
   I've been writing some system classes in StormC/C++ v3. I have written a threadable class (similar to Thread in java) that encapsulates a dos Process. Everything is fine apart from exception handling. Whenever any given thread method throws an exception, it seems that the actual task that threw it isn't always the one to catch it.
  For example, the protected GoIdle() method only ever throws an IllegalAccess if not called by the internal task. Other methods eg Wake() thow exceptions if they are called by the internal task.
  So imagine our thread is sleeping via GoIdle(). The only exception it is expecting is IlegalAccess, which shouldn't happen anyway because it has been called by the internal task. Everything is fine so far. Now imagine the parent task calls some method such as Start() that will throw AlreadyRunning. The internal thread ends up catching this!!
  Have actually managed to prove this by catching AlreadyRunning from the following fragment

  /* this code executed by internal task */
  try {
    GoIdle();
  }
  catch (AlreadyRunnging) {
  // not even thrown by GoIdle()!!
  cerr << "Bloody Hell!\n";
  }
  catch (IllegalAccess) { /* Nowt to do */  }
 
  Basically the whole thing then crashes as the wrong stack is unwound!
   I'm aiming for portability and really want to use execptions for error handling rather than having to use return values etc. Any help welcome!!!
int p; // A
 

Offline DaveP

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2116
    • Show only replies by DaveP
Re: Exception troubles!
« Reply #1 on: January 22, 2003, 07:50:07 AM »
Well a simple test I did with GCC last night worked
fine.

When you throw an exception a stack unwind occurs
rapidly.

The problem might be the way StormC handles the
stack unwind when two tasks are present in the same context.  If I recall correctly task creation
requires part of the stack passed as a pointer but
I need to go look at docs.

My current working theory is that StormC does not
differentiate between tasks during a stack unwind.

This is Blade's area and I haven't seen
him on here for a bit since he was sent death threats.

Anyway... still working on this but I thought I would
make sure you knew I was still looking.

Have you tried this without using the dos process implementation - say use an exec task instead? That would be much easier to debug.
Hate figure. :lol:
 

Offline KarlosTopic starter

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Exception troubles!
« Reply #2 on: January 22, 2003, 09:30:47 AM »
Thanks!

Can't hang about today, so I'll probably be offline when you read this...

I also think that the problem lies in StormC implementation. I have catalogued some serious problems with StormC v3 over the time I have been using it. For example, my major gripes are

1. Broken function template instansation, eg