Answered by:
For "Exception",is there some code or tag to specify the type of exception

Question
-
hi
i'd like to ask, for "Exception",is there some code or tag to specify the type of exception.
i know there is ex.message,but i dont want to use it,since i'd like to just know the type of exception
thank u very much
best regards
martin
Monday, August 4, 2014 7:59 AM
Answers
-
Hi,
You can use
caughtException.GetType().Name
- Proposed as answer by Magnus (MM8)MVP Monday, August 4, 2014 8:25 AM
- Marked as answer by martinwang1985 Monday, August 4, 2014 8:48 AM
Monday, August 4, 2014 8:23 AM -
i'd like to ask, for "Exception",is there some code or tag to specify the type of exception. i know there is ex.message,but i dont want to use it,since i'd like to just know the type of exception
The keyword in your question and for the answer is: type. Act on the type of the exception. See Best Practices for Exceptions. E.g.
public void MethodWithHandlers() { try { DoWork(); } catch (StackOverflowException e) { // Handle the exception and // continue executing. } catch (OutOfMemoryException e) { // Handle the exception and // continue executing. } }
- Marked as answer by martinwang1985 Monday, August 4, 2014 8:49 AM
Monday, August 4, 2014 8:28 AM
All replies
-
Hi,
You can use
caughtException.GetType().Name
- Proposed as answer by Magnus (MM8)MVP Monday, August 4, 2014 8:25 AM
- Marked as answer by martinwang1985 Monday, August 4, 2014 8:48 AM
Monday, August 4, 2014 8:23 AM -
i'd like to ask, for "Exception",is there some code or tag to specify the type of exception. i know there is ex.message,but i dont want to use it,since i'd like to just know the type of exception
The keyword in your question and for the answer is: type. Act on the type of the exception. See Best Practices for Exceptions. E.g.
public void MethodWithHandlers() { try { DoWork(); } catch (StackOverflowException e) { // Handle the exception and // continue executing. } catch (OutOfMemoryException e) { // Handle the exception and // continue executing. } }
- Marked as answer by martinwang1985 Monday, August 4, 2014 8:49 AM
Monday, August 4, 2014 8:28 AM -
thank you very much for your kindness help from heart, Ioana :)
best regards
martin
Monday, August 4, 2014 8:49 AM -
thank u very much Stefan
best regards
martin
Monday, August 4, 2014 8:49 AM