I have this code that simply validates a date, but ends the script if a error occurs (exit ()
).
Now i want to put this same code in a single function that returns false
on error.
I dont want to use "if/else". I want to return false
o开发者_如何学Pythonn error and stop execution of the others things.
Is that possible?
Learn exceptions. Live them. Love them.
you could change
exit ("Error !");
to
return false;
but exceptions would definitely be better as suggested by Ignacio Vazquez-Abrams
I see you already have your answer, but as a side note, are you aware that there is a php function that replaces a big part of your function: checkdate()
No need for regex's, if statements, etc.
精彩评论