Wahid Masud
Wahid Masud

Reputation: 1093

get php error, warning, notice and alert them with javascript

Well the title says it all. I want to get any php error, warning, notice and alert them via JavaScript in my own format. Is that possible? If yes then how? I have tried this but it won't catch warnings or notices i guess.

try{
    $result = oci_parse($conn, $query);
    oci_execute($result);
}catch(Exception  $e){
    echo 'Caught exception: ',  $e->getMessage(), "\n";  
    ///////////or anything to alert with JavaScript///////////
}

Upvotes: 0

Views: 2059

Answers (2)

Wahid Masud
Wahid Masud

Reputation: 1093

I just used JavaScript and got the error text. For those who have faced similar problem:

$('.xdebug-error').find("th:first").text();  

It will get the error text. If its a warning then just changing the class to 'xe-warning' would do the work! Now its possible to format the text and alert it as the user requires.

Upvotes: 0

Preethi Mano
Preethi Mano

Reputation: 445

Try this piece of code :

<?php
try{
$result = oci_parse($conn, $query);
oci_execute($result);
}
catch(Exception  $e){
echo '<script language="javascript">';
echo 'alert("Caught exception")';  
echo '</script>';
}
?>

Updated based on your comment

<?php
session_start();

//set this in your catch block
$_SESSION['flash'] = 'message'; 

//check for it in everypage.
if(isset($_SESSION['flash']) && !empty($_SESSION['flash']))
{
   echo '<div id="flash_container">'.$_SESSION['flash'].'</div>';
   unset($_SESSION['flash']);
}
?>

Or try this

http://mikeeverhart.net/php-flash-messages/

Upvotes: 1

Related Questions