Menu
SuiteCRM dedicated support by SalesAgility
Welcome, Guest
Username: Password: Remember me

TOPIC: How to catch exceptions?

How to catch exceptions? 2 months 1 day ago #72861

  • rainolf
  • rainolf's Avatar
  • Offline
  • Elite Member
  • Posts: 163
  • Thank you received: 2
  • Karma: 1
Hi,
i'm writing my custom scheduler function where a PDO connection is made to retrieve some information.

I've create, like usual, a try and catch block in order to catch exceptions but it won't works.

Any suggestion on this?

Regards
The administrator has disabled public write access.

How to catch exceptions? 1 month 4 weeks ago #72903

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 8568
  • Thank you received: 1313
  • Karma: 313
Even though this is a PHP question, we can try helping... but we would have to see the code. Often the problem is just a small detail or even punctuation... it is only possible to see by reading the exact code.

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

How to catch exceptions? 1 month 3 weeks ago #72971

  • rainolf
  • rainolf's Avatar
  • Offline
  • Elite Member
  • Posts: 163
  • Thank you received: 2
  • Karma: 1
Yes...sure

Just for example...a simple pdo connection to external database:

function importHubs(){
$GLOBALS->FATAL('************************ Hubs Import START ********************************');
$GLOBALS->FATAL('*************** Connecting to DATAWAREHOUSE *************');
try{
$dsn = "mysql:host=<wrong host>.;dbname=<database name>";
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
$PDOconn = new PDO($dsn, "username" , "password", $options);
} catch (PDOException $e){
$GLOBALS->FATAL('*************** OPS !!!!! NOT CONNECTED to DATAWAREHOUSE *************');
$GLOBALS->FATAL($e->getMessage());
return false;
}

//$PDOconn->query("bla bla bla");
$GLOBALS->FATAL('*************** WHAO !!!!! CONNECTED to DATAWAREHOUSE *************');
return true;
}

This script for example does not generate any exception.

Using it outside SuiteCRM the exception was captured....


Any hint?

Regards
The administrator has disabled public write access.

How to catch exceptions? 1 month 3 weeks ago #72979

  • rainolf
  • rainolf's Avatar
  • Offline
  • Elite Member
  • Posts: 163
  • Thank you received: 2
  • Karma: 1
Sorry...the example above seems to work.

Maybe some typo in my previous code.

This can be considered as solved.

really sorry
The administrator has disabled public write access.
Time to create page: 0.069 seconds
Powered by Kunena Forum