'How can I extend the TRY/CATCH to handle Regular Expression Errors
I am writing a BOT that uses a lot of Regular Expressions, sometimes to get one piece of information, depending on the HTML (it gets randomised to stop people like me from finding what I want and taking it ... ) so I will go through a number of regular expressions to obtain X or Y piece of data, such as a name, score, size, weight etc etc.
Is there a way of extending the TRY/CATCH handler so that if it fails on a Regular Expression I have a catch block just for that which would let me log the expression, the HTML I was looking at, and other info without throwing the error.
It's just I have a lot of regular expressions and I don't want to set global flags before the regex execution so that if it fails in the catch, I check the global flag and if true, I know it was a regex that was being executed, so I can then log different info than if something else might have triggered it.
Or you may say that is the best way rather than overriding system code etc.
I have just come out of hospital - again, I do believe I was in there this time last year and not a single power shower on the ward worked, anyway the morphine they have given me is pretty strong so please don't blame me for a stupid question as I would have probably searched a lot more for an answer before asking for help. I am thinking that the flag way is the best way forward rather than extending code I probably shouldn't be but maybe there is already a RegEx failure catch I've missed. #
If I go the flag way I can put a generic error handler in the catch block that checks for that flag and if it finds it logs the regex, html and x y z all in my log file rather than throwing the error which I would do for other errors but with this I want a detailed error report in my log file.
Ideas?
Thanks in advance for any help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
