对于转化string s

try
{
  int year = int.Parse(s);
}

 

异常            条件

ArgumentNullException  s 为 null 引用(在 Visual Basic 中为 Nothing)

FormatException      s 的格式不正确

OverflowException      s 表示小于 MinValue 或大于 MaxValue 的数字

那么如何处理异常呢?只需在下面加入下面的函数:

 

catch (Exception)
{

  system.out.println("wrong input!");
  return 0;
}

这样就解决了。

相关文章:

  • 2021-12-10
  • 2021-11-11
  • 2022-12-23
  • 2021-08-09
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2021-08-21
  • 2021-05-25
  • 2021-10-17
  • 2022-01-04
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案