CodeIgniter Forums
How handle the warnings - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How handle the warnings (/showthread.php?tid=35083)



How handle the warnings - El Forum - 10-19-2010

[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();
}



How handle the warnings - El Forum - 10-19-2010

[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


How handle the warnings - El Forum - 10-19-2010

[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...


How handle the warnings - El Forum - 10-21-2010

[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]