Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • You can't assign Exception to a string... Did you mean to do status = ex.Message? Commented Aug 24, 2014 at 4:48
  • Don't you see...ex is a variable of type Exception, and status is a string? status = ex.ToString(); is what technically does what you're looking for, but I won't say this is a good exception handling design... Commented Aug 24, 2014 at 4:49
  • You should catch the specific types of exceptions happening, and create an enumeration for them so you could have properties like ErrorType and ErrorMessage. With ErrorType.Success being 0 in the enumeration. Or something like that. Using a string to drive a status in c# is a really bad design. Enumerations are much more reliable and easier to work with. Also, ToString on an enumeration will spit out the values name. And you can use Enum.Parse to parse a name into it's enumeration value. Commented Aug 24, 2014 at 4:59
  • @Ryios what if its a custom response from a WebException? Commented Aug 24, 2014 at 5:04
  • What are you trying to accomplish here? If you can't handle an exception, don't catch it. Commented Aug 24, 2014 at 5:26