Best practices for Catching and throwing the exception

c#, exception

Solution

Generally you can be more explicit.

In this case, you can throw a

ArgumentException

The more specific you are, the easier it is for other code to handle the exception.

This allows you to do

try
{
    GetshortMsgCode("arg")
}
catch(ArgumentException e)
{
    //something specific to handle bad args, while ignoring other exceptions
}

Problem

In msdn link, it is mentioned that Do not throw System.Exception or System.SystemException. In my code i am throwing like this ``` private MsgShortCode GetshortMsgCode(string str) { switch (str.Replace(" ","").ToUpper()) { case "QNXC00": return MsgShortCode.QNXC00; default: throw new Exception("Invalid message code received"); } } ``` is this a bad practice??

Original source