【发布时间】:2014-04-19 16:42:52
【问题描述】:
在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" } }
【问题讨论】:
标签: haskell error-handling io