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 7751657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:36:16+00:00 2026-06-01T11:36:16+00:00

My question is how can I return a nil from an exception instead of

  • 0

My question is how can I return a nil from an exception instead of — in the case of using slurp — the file name that would not load and the exception text? Here are the details.

I want the following code to return a nil:

(defn open-csv-file
    "Attempts to open a .csv file and complains if the file is not present."

    [file-name]
        (let [file-data 
            (try 
                (slurp file-name)
                (catch Exception e (.getMessage e)))]
            file-data))

Here is an example of what is being returned now.

bene-cmp.core=> (load-file "src/bene_cmp/core.clj")
#'bene-cmp.core/-main
bene-cmp.core=> (def x  (open-csv-file "test_file.csv"))
#'bene-cmp.core/x
bene-cmp.core=> x
"test_file.csv (No such file or directory)"
bene-cmp.core=> 

I am trying to avoid modifying this function, so that it throws the exception and then having the caller use a try/catch block.

Thank You.

  • 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-06-01T11:36:18+00:00Added an answer on June 1, 2026 at 11:36 am

    If I understand your question, you just need to change this:

    (catch Exception e (.getMessage e)))]
    

    to this:

    (catch Exception e))]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is very similar to another recent question: How can I return the current
My question can be boiled down to, where does the string returned from stringstream.str().c_str()
I have not been able to find any definitive answers to this question: Can
First, sorry for my English, im not an American. My question is how can
I am receiving xml from a webservice call that contains a nil=true : <cacheEntry>
The short question is: How can I get iPhone (objective-c) file operations to work
From this question, I know you can use SecKeychainFindGenericPassword without a username value. It
Say that I have the Python code: someString = file(filename.jpg).read() How can I replicate
One would think I can easily find an answer to this question, and perhaps
I have a hash that I'm getting from using JSON.parse. I am inserting into

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.