CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • is it possible to catch db write exceptions to log and continue process
Pages: [1]

Author Topic: is it possible to catch db write exceptions to log and continue process  (Read 1200 times)

saffrongeek

  • Guest
is it possible to catch db write exceptions to log and continue process
September 19, 2009, 11:40:03 am
Hi ,

      I have written a script to do some data migration to crm database and also could successfully invoke the hook do some custom tasks before db write. But , I just figured out a scenario that if for some reason crm contact update / insertion happens duplication, it throws error message to screen and stops.

      I dont know whether there is a throw and catch exception possibility in CRM for DB operations. Any good pointer links to learn and use for my need? Please share with me. Thanks in advance,

With regards

saffrongeek

ruid

  • I post occasionally
  • **
  • Posts: 46
  • Karma: 4
Re: is it possible to catch db write exceptions to log and continue process
September 28, 2009, 07:30:42 pm
As I understand, if you using API it won't stop the script.
You can store the error message during your importing.
Eg
Code: [Select]
$params = array(
                    'first_name'    => 'Dan',
                    'last_name'     => 'Conberg',
                    'email'         => 'dan.conberg@myco.com',
                    'contact_type'  => 'Individual'
                    );
$contact =&civicrm_contact_add( $params );
if ( civicrm_error ( $contact )) {
    $error_message[]="contact_add_error: ".$contact['error_message'];
}

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: is it possible to catch db write exceptions to log and continue process
September 29, 2009, 10:24:59 am
I think you can use this method to spit out variable values, messages, etc. to the CiviCRM log file:

CRM_Core_Error::debug_log_message();
Protect your investment in CiviCRM by  becoming a Member!

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • is it possible to catch db write exceptions to log and continue process

This forum was archived on 2017-11-26.