| 
 Posted by gosha bine on 06/11/07 13:01 
On 10.06.2007 14:36 Sergei Shelukhin wrote: 
> Hi. 
> I need to handle warnings in incorrect regular expressions executed 
> using preg_match. 
> Warnings shouldn't appear, instead I want to output some generic 
> message like: "Bad regex: $regex" and also do a database change. 
> I tried using try-catch but warnings are not caught. 
> What do I do? 
>  
 
The "natural" way is to use exceptions. First, install generic  
errors-to-exceptions handler (see Exceptions man page). Then, just  
enclose preg code in a try-catch block: 
 
try { 
    preg_match($regex, ...) 
} catch(ErrorException $e) { 
    echo "Bad regex: $regex"; 
} 
 
--  
gosha bine 
 
extended php parser ~ http://code.google.com/p/pihipi 
blok ~ http://www.tagarga.com/blok
 
[Back to original message] 
 |