vb.net
Try
'ファイルを開く
sr = System.IO.File.OpenText(filePath)
Catch ex As System.IO.FileNotFoundException
System.Console.WriteLine(ex.Message)
Return Nothing
Catch ex As System.IO.IOException
System.Console.WriteLine(ex.Message)
Return Nothing
Catch ex As System.UnauthorizedAccessException
System.Console.WriteLine(ex.Message)
Return Nothing
Catch ex As System.Exception
'すべての例外をキャッチする
'例外の説明を表示する
System.Console.WriteLine(ex.Message)
Return Nothing
End TryC#
try
{
//ファイルを開く
sr = System.IO.File.OpenText(filePath);
}
catch (System.IO.FileNotFoundException ex)
{
System.Console.WriteLine(ex.Message);
return null;
}
catch (System.IO.IOException ex)
{
System.Console.WriteLine(ex.Message);
return null;
}
catch (System.UnauthorizedAccessException ex)
{
System.Console.WriteLine(ex.Message);
return null;
}
catch (System.Exception ex)
{
//すべての例外をキャッチする
//例外の説明を表示する
System.Console.WriteLine(ex.Message);
return null;
}