Welcome Guest, Not a member yet? Register   Sign In
How handle the warnings
#1

[eluser]vamsee[/eluser]
I got following warning


Severity: Warning

Message: Division by zero


But i would like to handle warning too.


This is my code

Code:
try
{
   echo 90/0;    
   throw new Exception("Divide by zero error");
}
catch(Exception $ex)
{
   echo $ex->getMessage();
}
#2

[eluser]n0xie[/eluser]
An exception is not a warning. Hence you can't 'catch' a warning, since it doesn't stop your script from executing. You could suppress the error (either by prepending it with an @ or set your ERROR LEVEL to something that suppresses the warning).

You could also change the behaviour of PHP when it encounters a warning by setting an error handler
#3

[eluser]WanWizard[/eluser]
You can also try to write code with proper validation, so the exception is caught and handled before it triggers a PHP warning...
#4

[eluser]vamsee[/eluser]
[quote author="vamsee" date="1287492578"]I got following warning [Solved]

Severity: Warning

Message: Division by zero


But i would like to handle warning too.


This is my code

Code:
try
{
   echo 90/0;    
   throw new Exception("Divide by zero error");
}
catch(Exception $ex)
{
   echo $ex->getMessage();
}
[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB