Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic SYNERGY (steve huntington)
Decrease font size
Increase font size
Topic Title: Catching errors with Perl API
Topic Summary:
Created On: 6-Jan-2004 15:25
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 6-Jan-2004 15:25
User is offline View Users Profile Print this message


Jean-Christophe Dhellemmes

Posts: 2
Joined: 6-Jan-2004

Hello,

I am using the ChangeSynergy Perl API for an integration project (with Siebel CRM). The problem is that when an error occurs in some functions (like Login for example), the function 'exits' the script so the calling code cannot catch and process the error (bad password in Login call for example).

I looked at the API modules source code, and indeed 'exit' is called instead of 'die' in the callCsapi() function (util.pm).

I would like to know if there is a proper way to catch errors in my Perl script. If not, what side effects should I fear if I replace 'exit' with 'die' in util.pm.

JC Dhellemmes
ActivCard
Report this to a Moderator Report this to a Moderator
 6-Jan-2004 21:18
User is offline View Users Profile Print this message


Don Levine

Posts: 5
Joined: 12-Jul-2003

You could try using an eval block and look at @$. The following example is using TK with Perl, but that is not required.

sub CS_Connect()
{
if ($debug) { print "Connecting to server...\n"; }

#Eval block is used for error handling.
eval
{
$csapi->setUpConnection("http", $cs_server, 8600);

#Login to the ChangeSynegy server. (user, password, role, database);
$aUser = $csapi->Login($userid, $passwd, "User", $database);
};

#If any errors occured, print them to the screen.
if ($@)
{
print $@;
$mw->messageBox(-title => "Error",
-type => 'OK',
-message => $@);
return 0; # error
}
else
{
return 1;
}
}

..Don
Report this to a Moderator Report this to a Moderator
 7-Jan-2004 09:30
User is offline View Users Profile Print this message


Jean-Christophe Dhellemmes

Posts: 2
Joined: 6-Jan-2004

Does this actually work for you? Does the if ($@) block ever get executed in case of error? I tried this myself (I followed the API documentation samples) without success.

My point is that the Login function ends up calling 'exit' and not 'die' so it never returns in case of error. I am not a Perl expert so I may be missing something.

I was able to make it work by replacing the 'exit' statements by 'die' in the callCsapi() function in util.pm but I'd rather avoid making changes in Telelogic's code.
Report this to a Moderator Report this to a Moderator
 7-Jan-2004 16:35
User is offline View Users Profile Print this message


Don Levine

Posts: 5
Joined: 12-Jul-2003

Yes, this did work for me (though it was formatted differently -- I lost the tabs on the way into the forum -- sorry). When the server processes were taken down, the client side (the Perl program in this case) received the $@ variable with a pretty descriptive message in it. In my case, I was running the Perl script from a Windows machine and the server was a different machine (running Linux). Maybe there are some environmental-specific factors that are affecting the results. Also, make sure you check $@ before executing anything else that might change its value. I am not a Perl expert either (yet), so I'm not sure all the things that can alter $@.

..Don
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic SYNERGY forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 15:34.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.