Difference between revisions of "Throw/Raise Exception From Probes"

From OC Systems Wiki!
Jump to: navigation, search
(Created page with "You can raise and Ada exception or throw a C++ exception from a probe. In Ada you will need to know the name of the exception you want to raise. This can be as simple as <co...")
 
m (Ada Example)
Line 14: Line 14:
 
==Ada Example==
 
==Ada Example==
  
 +
The Ada example demonstrates how to raise an Ada exception from a probe on_entry/on_line/on_exit action.  Note that <code>#ifdef's</code> are used to condition the Aprobe macro used to raise the exception depending on the target compiler (PowerAda or Gnat).
 +
 +
<source lang=c>
 +
#ifdef _AIX
 +
#define RAISE ap_RaisePowerAdaException
 +
#else
 +
#define RAISE ap_RaiseGnatException
 +
#endif
 +
 +
probe thread
 +
{
 +
  probe "tmain.x1"
 +
  {
 +
      on_entry
 +
      {
 +
        RAISE("constraint_error");
 +
      }
 +
  }
 +
 +
  probe "tmain.x2"
 +
  {
 +
      on_exit
 +
      {
 +
        RAISE("ada.io_exceptions.status_error");
 +
      }
 +
  }
 +
 +
  probe "tmain.x3"
 +
  {
 +
      on_line(27)
 +
      {
 +
        RAISE("my_exception");
 +
      }
 +
  }
 +
}
 +
</source>
  
 
==C/C++ Example==
 
==C/C++ Example==

Revision as of 01:58, 18 August 2019

You can raise and Ada exception or throw a C++ exception from a probe.

In Ada you will need to know the name of the exception you want to raise. This can be as simple as constraint_error or a more complex fully-qualified name pkg.child.my_exception.

In C++ you will have to provide: the exception object (usually referenced in the application program using a target expression, for example $MyExceptionObject), the exception typeinfo, a constructor, and a destructor. Below are some prototype macros which make this a little bit easier.

If you raise/throw and exception in an on_entry action of a probe, the function call will be stubbed and the exception will be raised/thrown when the probed function exits.

If you raise/throw and exception in an on_line/offset action of a probe, the exception will be raised/thrown at that point.

If you raise/throw and exception in an on_exit action of a probe, the exception will be raised/thrown when the function returns.


Ada Example

The Ada example demonstrates how to raise an Ada exception from a probe on_entry/on_line/on_exit action. Note that #ifdef's are used to condition the Aprobe macro used to raise the exception depending on the target compiler (PowerAda or Gnat).

#ifdef _AIX
#define RAISE ap_RaisePowerAdaException
#else
#define RAISE ap_RaiseGnatException
#endif

probe thread
{
   probe "tmain.x1" 
   {
      on_entry 
      {
         RAISE("constraint_error");
      }
   }

   probe "tmain.x2" 
   {
      on_exit 
      {
         RAISE("ada.io_exceptions.status_error");
      }
   }

   probe "tmain.x3" 
   {
      on_line(27) 
      {
         RAISE("my_exception");
      }
   }
}

C/C++ Example