Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string into exception

Tags:

c#

exception

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.

like image 769
Mathematics Avatar asked Aug 30 '13 13:08

Mathematics


People also ask

How to Convert null string to int in c#?

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.

Which way will attempt to convert a string to an integer without throwing an exception?

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.

How do I convert an exception to a string in Python?

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.


1 Answers

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");
like image 83
Rob G Avatar answered Oct 06 '22 18:10

Rob G