에서 예외를 무시하는 방법 정상적인 프로그램 실행 중에 예외가 발생할 수 있습니다.F #
나는 그것을 알고 있고 그것을 그냥 무시하고 싶습니다. 어떻게 이것을 F #에서 얻을 수 있습니까?
let sha = new SHA1CryptoServiceProvider()
let maxLength = 10000
let fileSign file =
let fs = File.OpenRead(file)
let mutable res = (0L, [|0uy|])
try
let flLen = fs.Length
let len = int (min (int64 maxLength) flLen)
// read 'len' bytes
let mutable pos = 0
while (pos < len) do
let chunk = fs.Read(buf, pos, len - pos)
pos <- pos + chunk
// get signature
let sign = sha.ComputeHash(buf, 0, len)
// store new result
res <- (flLen, sign)
with
| :? IOException as e -> e |> ignore
finally
if (fs <> null) then
fs.Dispose()
res
경고는 다음과 같습니다 :
는 error FS0010: Unexpected keyword 'finally' in binding. Expected incomplete structured construct at or before this point or other token.
내가 원하는에 대한 해당 C#을 동등한은 다음과 같습니다
FileStream fs = null;
try
{
fs = File.OpenRead(file);
// ... other stuff
}
catch
{
// I just do not specify anything
}
finally
{
if (fs != null)
fs.Dispose()
}
여기
는 경고와 함께 컴파일 내 코드입니다 F #에서with
블록을 생략하면 예외가 무시되지 않습니다.