在
System.Directory
库中,getPermissions
函数可能会返回IO错误。文档说明可能会失败,其中包括isPermissionError
或isDoesNotExistError
。我该如何处理在调用getPermissions
时发生的IO错误?input <- try (do
permissions <- getPermissions filepath
print permissions)
case input of
Left e -> print "a"
Right e -> print "b"
错误:
No instance for (Exception e0) arising from a use of ‘try’
The type variable ‘e0’ is ambiguous
Note: there are several potential instances:
instance Exception NestedAtomically
-- Defined in ‘Control.Exception.Base’
instance Exception NoMethodError
-- Defined in ‘Control.Exception.Base’
instance Exception NonTermination
-- Defined in ‘Control.Exception.Base’
...plus 7 others
In a stmt of a 'do' block:
input <- try
(do { permissions <- getPermissions filepath;
print permissions })
In the expression:
do { input <- try
(do { permissions <- getPermissions filepath;
print permissions });
case input of {
Left e -> print "a"
Right e -> print "b" } }
In an equation for ‘checkwritefilepermissions’:
checkwritefilepermissions filepath
= do { input <- try
(do { permissions <- getPermissions filepath;
print permissions });
case input of {
Left e -> print "a"
Right e -> print "b" } }