In a library, a System.Directoryfunction getPermissionsmay return I / O errors. The documentation states that it may fail with isPermissionErroror isDoesNotExistError. How to handle I / O errors during a call getPermissions?
Attempt:
input <- try (do
permissions <- getPermissions filepath
print permissions)
case input of
Left e -> print "a"
Right e -> print "b"
Error:
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" } }
source
share