Haskell - 使用readProcess时profiling抛出异常

时间:2016-02-09 05:58:35

标签: haskell exception profiling ghc

我已经开始分析我开发的算法,但我遇到了一个令人困惑的例外。

我的程序调用外部进程。我正在使用System.Process中的readProcess进行此调用。当我构建(ghc 7.8.4)而没有-prof标志时,程序运行良好,没有任何异常。当我使用-prof标志,然后使用+ RTS -xc -RTS执行时,我会在每个readProcess事件中获得异常。

我已将代码缩减为基于Linux的简单示例。

ProfTest.hs:

module Main where

import System.Process
import Control.Exception

main = catch (readProcess "cat" [] "foo" >>= putStrLn)
             (\e -> putStrLn $ show (e :: SomeException))

然后按如下方式构建/运行:

$ ghc -prof ProfTest.hs
$ ./ProfTest +RTS -xc
*** Exception (reporting due to +RTS -xc): (THUNK_1_0), stack trace: 
  Main.CAF
Hello

导致此例外的原因是什么?

简单的解决方案是将-xc标志替换为-p或另一个不转储异常堆栈的选项。但我很困惑为什么在这种情况下监视异常会导致异常。

有什么想法吗?

提前致谢!

0 个答案:

没有答案