locked
For "Exception",is there some code or tag to specify the type of exception RRS feed

  • 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

    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.		
    	}
    }

    Monday, August 4, 2014 8:28 AM

All replies

  • Hi,

    You can use

    caughtException.GetType().Name

    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.		
    	}
    }

    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