C# - failed parse exception?

后端 未结 10 1412
春和景丽
春和景丽 2021-02-19 07:35

I am writing a program in C#, and I want to catch exceptions caused by converting \"\" (null) to int. What is the exception\'s name?

EDIT: I\'m not sur

10条回答
  •  自闭症患者
    2021-02-19 08:00

    Let's have a look at the documentation (which is a much cleaner solution that "trying it out"):

    public static int Parse(string s)

    [...]

    Exceptions:

    • ArgumentNullException: s is null.
    • FormatException: s is not in the correct format.

    This should answer your question. As others have already mentioned, maybe you are asking the wrong question and want to use Int32.TryParse instead.

提交回复
热议问题