Take a look at the .InnerException
property of the exception.
See the MSDN Documentation about it.
You can also use the .ErrorCode
property or just use the hash code generated by the message, which will be different for each error message:
ex.Message.GetHashCode