Question
· Dec 19, 2019

Catch Adapter error in a Try/Catch

Hello,

I would like to catch an Adapter error in a try/catch. I have a problem with SMTP and SFTP adapter when the connection failed after 15 seconds.

 Here is an example of my code for the SFTP adapter:

Try{
  ... //creating a stream file character
 
 //Trying to get a Status error if the PUTSTREAM doesn't work
 set tSC = ..Adapter.PutStream("file.pdf",streamfile)
 //If any error : throw
 if $$$ISERR(tSC) THROW tSC
}catch Exception{
 set pOutput= ##class(MyResponse).%New()
 set pOutput.errorString = Exception.DisplayString()
}

The problem is that the error isn't catch :  it ends as an ErrFailureTimeout :


I tried to change the "ReplyCodeAction" parameter on the operation , to change it to "E=C" , which mean that if there is an error, the message continue , but it didn't change anything.

 

Do you have any idea on how can I catch the errFailureTimeout Error ? 

Am I doing something wrong ? ( is the ReplyCodeAction on the operation false ? ) 

 

Thank you in advance for your reply. 
Best regards,

 

BOURRE LUCAS 

Discussion (5)0
Log in or sign up to continue

Hello Eduard,

I'm sorry i guess i didn't explain well my problem.
The PutStream method is in EnsLib.FTP.OutboundAdapter , not in Email.OutboundAdapter  .
I was looking for a property, or a parameter that is available on outbound adapters to avoid "error failure timeout"  .
For example, if I try to send a mail in the Email Adapter via the method "SendMail" , without puting any SMTP Server, I will have an "error failure timeout" because the SMTP Server is not found.
I have the same problem in the FTP Adapter via the method "PutStream" 

Best regards

Hi

Would it be possible to send me your Business Operation code. It is difficult to debug these things without a complete picture of what you are attempting to do,

You can either attach the xml export of the class to this thread or mail it to me at nigel.salm@outlook.com

I get the idea that if the FTP or SMTP servers are not defined you will get the error you get. Is there a reason why they are not specified?

In your code you can always test to see if the ..Adapter.{server} is defined and throw an elegant error rather than wait for the adapter to go through the process of attempting to connect to the the server and then failing,

You can always play with the connection time outs etc so a screen shot of you  business operation production item values would be helpful

Yours

Nigel

My guess is that you need to specify Exception as a Status i.e.:

Exceptuion.AsStatus()

and then your code should read

set pOutput=##class(MyResponse).%New()

set sc=Exception.AsStatus()

set pOutput.errorString=$system.GetErrorText(sc)

but another thought:

If your method quits with tSC (as a %Status) then presumably your method quits with

quit tSC

in which case instead of trowing tSC just quit your Try {} with quit tSC

and in your catch write it as follows:

catch Exception {

   set tSC=Exception .As Status()

}

set pOutput=##class(MyResponse).%New()

set pOutput.errorString=$s(tSC:"",1:$system.Status.GetErrorText(tSC))

quit tSC