Try / Catch and Async methods

  • Thread starter Thread starter Peter Oliphant
  • Start date Start date
P

Peter Oliphant

In the System::Speech namespace there asychronous methods on both the SR and
TTS sides. For example, RecognizeAsync( ) and SpeakAsync( ). For the
purposes of this discussion, it isn't important what these methods do, but
how they do them. That is, upon executing these methods, they do not
necessarily complete what they are intended to do before the code execution
moves past them to the following instructions. When they are done they
typically will cause an Event to happen that notifies the program the
operation is done.

I have a case where the operation of such an asynchronous function is
causing a system exception error. Is it possibly to try-catch such an
exception? Will putting the asynchronous method do it, something like:

try
{
MethodAsynch();
}
:
:
catch(...)
{
//...
}

Will wrapping the entire application's execution do it:

try
{
main()
{
//all code, contains any asynch method calls
}

catch(...)
{
//...
}

Will both/neither of these methods work? Assuming it is possible, what is
the way typically used?

Thanx!

[==Peter==]
 
In the System::Speech namespace there asychronous methods on both the SR and
TTS sides. For example, RecognizeAsync( ) and SpeakAsync( ). For the
purposes of this discussion, it isn't important what these methods do, but
how they do them. That is, upon executing these methods, they do not
necessarily complete what they are intended to do before the code execution
moves past them to the following instructions. When they are done they
typically will cause an Event to happen that notifies the program the
operation is done.

I have a case where the operation of such an asynchronous function is
causing a system exception error. Is it possibly to try-catch such an
exception? Will putting the asynchronous method do it, something like:

try
{
MethodAsynch();
}
:
:
catch(...)
{
//...
}

Will wrapping the entire application's execution do it:

try
{
main()
{
//all code, contains any asynch method calls
}

catch(...)
{
//...
}

Will both/neither of these methods work? Assuming it is possible, what is
the way typically used?

The function that is executed asynchronously should do the try/catch. You
can write a wrapper function for this if need be.
 
Peter Oliphant said:
In the System::Speech namespace there asychronous methods on both the SR
and TTS sides. For example, RecognizeAsync( ) and SpeakAsync( ). For the
purposes of this discussion, it isn't important what these methods do, but
how they do them. That is, upon executing these methods, they do not
necessarily complete what they are intended to do before the code
execution moves past them to the following instructions. When they are
done they typically will cause an Event to happen that notifies the
program the operation is done.

I have a case where the operation of such an asynchronous function is
causing a system exception error. Is it possibly to try-catch such an
exception? Will putting the asynchronous method do it, something like:

try
{
MethodAsynch();
}
:
:
catch(...)
{
//...
}

Will wrapping the entire application's execution do it:

try
{
main()
{
//all code, contains any asynch method calls
}

catch(...)
{
//...
}

Will both/neither of these methods work? Assuming it is possible, what is
the way typically used?

I would not expect either method to work.

Catch the exception in the debugger and find out what thread it appears on.
If it isn't a thread you created, I don't think you will be able to
interpose an exception handler.
Thanx!

[==Peter==]
 
I think this approach might work. I can't test it since the problem I had is
now gone:

main()
{
try
{
// application code
}
catch(...)
{
// process error
}
return 0 ;
}

[==Peter==]

Ben Voigt said:
Peter Oliphant said:
In the System::Speech namespace there asychronous methods on both the SR
and TTS sides. For example, RecognizeAsync( ) and SpeakAsync( ). For the
purposes of this discussion, it isn't important what these methods do,
but how they do them. That is, upon executing these methods, they do not
necessarily complete what they are intended to do before the code
execution moves past them to the following instructions. When they are
done they typically will cause an Event to happen that notifies the
program the operation is done.

I have a case where the operation of such an asynchronous function is
causing a system exception error. Is it possibly to try-catch such an
exception? Will putting the asynchronous method do it, something like:

try
{
MethodAsynch();
}
:
:
catch(...)
{
//...
}

Will wrapping the entire application's execution do it:

try
{
main()
{
//all code, contains any asynch method calls
}

catch(...)
{
//...
}

Will both/neither of these methods work? Assuming it is possible, what is
the way typically used?

I would not expect either method to work.

Catch the exception in the debugger and find out what thread it appears
on. If it isn't a thread you created, I don't think you will be able to
interpose an exception handler.
Thanx!

[==Peter==]
 
Back
Top