PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This is confusing. Can anybody tell me what is the obvious difference between throwing an exception and using trigger_error() function ? According to my knowledge, exception are used to handle runtime error and if that's the case
Errors and exceptions are quite different. Errors aren't necessarily fatal, and can be routed through custom error handling functions if required. Exceptions are fatal if not handled (caught) and can be routed through custom Exception classes.
In your example, you would use trigger_error() if the user must enter a number > 1 and you want to inform them of that fact. You'd use exceptions if you were deep in a backend and a number > 1 was cause for a program exit.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
I agree with astions, errors are for logging and maintenance / debugging purposes. I would not consider form validation failure to be an "error" in that sense. As an aside, I wouldn't use 80% of the code samples in the manual, as they are, in a real project.