Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4573878
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:50:47+00:00 2026-05-21T19:50:47+00:00

Ok, guys, super easy question (it seems weird that Google didn’t help me with

  • 0

Ok, guys, super easy question (it seems weird that Google didn’t help me with this one):

import IO

--.... yadda, yadda, yadda

  file <- openFile "/some/path" ReadMode

How do I check if the handle that I got from openFile is a valid handle, i.e. that the file exists and was opened successfully?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:50:48+00:00Added an answer on May 21, 2026 at 7:50 pm

    If the file doesn’t exist, or some other error occurs, the call to openFile will fail with an exception.

    For example:

    import System.IO
    
    main = do
       openFile "/some/path" ReadMode
    

    Fails with:

    A.hs: /some/path: openFile: does not exist (No such file or directory)
    

    The types of exception that may be thrown by openFile are listed here, and include:

    • isAlreadyInUseError if the file is already open and cannot be reopened;
    • isDoesNotExistError if the file does not exist; or
    • isPermissionError if the user does not have permission to open the file.

    You can catch these errors using Control.Exception, like so:

    {-# LANGUAGE ScopedTypeVariables #-}
    
    import System.IO
    import Control.Exception
    
    main = do
        handle (\(e :: IOException) -> print e >> return Nothing) $ do
          h <- openFile "/some/path" ReadMode
          return (Just h)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question that i hope you guys can help me with! This
Hi Guys could you please help me refactor this so that it is sensibly
Hi Guys can you please help me with this error? What is it? Server
Hi guys this question may look to be very silly. But still i have
OK guys fine..., seems like I was wrong from the last question... I'm working
Hey guys, I have this code within a function inside a class that is
Guys I asked a similar question like this earlier since I was unable to
Ok guys and gals, here is my problem: I've built a custom control that
Hi guys I wrote this code and i have two errors. Invalid rank specifier:
Hi guys I was looking at this code but I'm struggling to understand what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.