Friday, June 28, 2013

How to handel warning error using exceotion in php

<?php
function custom_error($errno, $errstr, $errfile, $errline){
echo "Xml url not valid $errfile";
die();
}
function getData() {
 if(!set_error_handler('custom_error')){
    echo "Error :";

    }

    try {
        $xml = new SimpleXMLElement('http://publisher.usb.api.shopping.com/publisher/3.0/reasdfst/GeneralSearch?apiKey=752d3653-2797-4544-9ca1-asdf&trackingId=sadf&numItems=1&&keyword=strollers', null, true);
    }catch(Exception $e) {
        restore_error_handler();

    }

    return $xml;
}

    $xml = getData();


?>

No comments:

Post a Comment