I want to convert a string into exception but not able to find any thing on google.
I am using C# .Net 2.0.
Reason is because third party client has a method that is logging method and only takes exception and i have a scenario where i must need to log something but using that method. so must need to convert string into exception.
Using the Convert Method Here, we have used Convert. ToInt32() method, the difference in Parse() and Convert. ToInt32() method is only that Convert. ToInt32() method always accept the null value return it.
TryParse() method will return false instead of throwing an exception. Thus, the TryParse() method is the safest way to converting numeric string to integer type when we don't know whether the string is a valid numeric string or not.
The except statement has been used here to get the exception error in variable “e”. The exception will be converted into a string i.e., str, and saved into the variable “string”. The string variable will be printed out in the shell at the end. Save the updated Python code with the Ctrl+S shortcut.
Exceptions are created as any other object, using the new
keyword. You can provide it a message argument that you can store your string in:
Exception e = new Exception("Your string goes here");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With