I'm trying to handle my exceptions based on regular expressions. To do this, all my constraints start the same way. (CCC_TABLE_COLUMN_TYPECONSTRAINT)
Ex:
CCC_USER_NAME_UNIQUE
CCC_BOOKS_TITLE_UNIQUE.
I'm not able to return the entire string.
try
{
await DbContext.SaveChangesAsync().ConfigureAwait(false);
}catch(Exception ex)
{
regex = new Regex("CCC");
var reg1 = regex.Match(ex.toString());
}
In reg1 only "CCC" is returned. How do I return the entire constraint name?
You need to include matching all the parts
CCC_[A-Z]+_[A-Z]+_[A-Z]+
Assuming you are only using upper case letters in the names. If not replace the [AZ]
with an expression that would match.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.