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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:33:28+00:00 2026-05-25T15:33:28+00:00

I have three functions I map over, I wish to stop evaluation upon catching

  • 0

I have three functions I map over, I wish to stop evaluation upon catching an exception.
I can catch the exception, but am not getting the behavior I want. It could be that I’m thinking about this problem in the incorrect way (maybe I shouldn’t be map a list of functions in this case), and would appreciate this being pointed out. Here’s what I think is the relevant code.

import qualified Control.Exception as C
data JobException = PreProcessFail
                  | JobFail
                  | ChartFail
                     deriving (Show, Typeable)

instance C.Exception JobException



type ProcessState = MVar ProcessConfig



data ProcessConfig = PConfig { model :: ServerModel
                             , ipAddress :: String
                             , cookie :: Cookie
                             } deriving Show

exceptionHandler :: JobException -> IO ()
exceptionHandler exception = do
   writeFile "testException.txt" ("caught exception " ++ (show exception))
-- much more functionality will be put here once I get the logic correct
preProcess :: ProcessState -> IO ()
preProcess sModel = do
   putStrLn ("preProcessing" )

initiateJob :: ProcessState -> IO ()
initiateJob sModel = do
   C.throw JobFail  
   putStrLn ("in progress")
makeChart :: ProcessState -> IO ()
makeChart sModel = do
     putStrLn ("chart making")

So now, when I test this out in ghci, this is what happens.

a <- mapM (flip Control.Exception.catch exceptionHandler) [preProcess world, initiateJob world, makeChart world]
Loading package filepath-1.2.0.0 ... linking ... done.
Loading package unix-2.4.2.0 ... linking ... done.
preProcessing
chart making

I should not be seeing the string “chart making”. How do I abort the evaluation of the list upon throwing an exception?

  • 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-25T15:33:29+00:00Added an answer on May 25, 2026 at 3:33 pm

    mapM maps the function then sequences the list. So you’ve got a catch around each action in the list separately. What you want is to sequence the list into a single action, and then catch the exception once so interrupting everything else in the list. The following works:

    (flip Control.Exception.catch exceptionHandler) $ sequence_ [preProcess world, initiateJob world, makeChart world]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ExtJS has Ext.each() function, but is there a map() also hidden somewhere? I have
I have an iphone app where I call these three functions in appDidFinishLaunching: glMatrixMode(GL_PROJECTION);
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
I have taken three textboxes over aspx page. A JavaScript function is associated with
I have 3 function in my class B. These three function have to access
I have three classes that all have a static function called 'create'. I would
I have a binary tree of functions and terminal values. I'd like to print
I have a function that receives three different people objects and generates a new
I have a ColdFusion function foo which takes three args, and the second two
I have a calc function in java script that takes three integer parameters, following

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.