![]() |
Telelogic SYNERGY (steve huntington) | ![]() |
Topic Title: Catching errors with Perl API Topic Summary: Created On: 6-Jan-2004 15:25 Status: Read Only |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
Telelogic SYNERGY
» SYNERGY/Change
»
Catching errors with Perl API
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.