![]() |
how to capture and show error in oop php to user?
hi, i am new to oop php programming style.. i am trying to write a image class to process images, but how do i capture the error(for example when you upload a non image file) and show it to the user?
PHP Code:
PHP Code:
Thanks in advance! |
Your code is sort of wrong, you cannot return a value in a contructor or destructor, you can only catch these sort of values if they are staticlly declared, but non of the magic methods may be declared staticlly.
To detect an error you should use Exceptions, instead of the return false part in your constructor you say: PHP Code:
PHP Code:
PHP Code:
For more information about the methods that the Exception class exposes, then referer to the php.net docs here: PHP: Exception - Manual |
Thank you Kally.
this is what i am looking for.. =) can you give an idea of how to use the capture message from the exception and display it to the user with style(css). |
Use the getMessage() from the exception class to print the error message set from the constructor
|
what about this, let say that i have caught a few error and i only want to show some of it(those that i want to show, those that would not lead to security issues), and hide the rest..
How do you do it? |
It sounds as though you may wish to use error handling, instead of exception handling, to me.
|
| All times are GMT. The time now is 08:57 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0