TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Asynchronous Exceptions in Practice

80 pointsby dmitover 8 years ago

4 comments

runeksover 8 years ago
&gt; The Haskell runtime keeps track of how much memory each Haskell thread has allocated in total, and if that total exceeds the limit we set, the thread receives an asynchronous exception, namely AllocationLimitExceeded. The user code running on our platform is not permitted to catch this exception, instead the server catches it, logs some data to aid debugging, and sends an error back to the client that initiated the request.<p>This is actually pretty cool. This way the server stays in charge of the threads it spawns, rather than having to build in some auto-destruct feature into the thread itself (which may not necessarily fire). The thread becomes more like a sandboxed environment -- with resource quotas -- than an independent entity, which I think is what we want, if we want to be able to reason about our code.
rkrzrover 8 years ago
&quot;You can throw an exception to another thread, at any time;&quot; &quot;The other thread will receive the exception immediately, whatever it is doing.&quot;<p>Does anybody know how this is implemented in the runtime system? How does one thread communicate with another thread? And how do you need to look at this for it <i>not</i> to be a side-effect?<p>Any insight is much appreciated.
评论 #13474542 未加载
评论 #13472734 未加载
评论 #13472509 未加载
danidiazover 8 years ago
A common pattern is trying to recorver from IO exceptions but treating asynchronous exceptions as fatal. The safe-exceptions package helps with that: <a href="http:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;safe-exceptions" rel="nofollow">http:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;safe-exceptions</a>
xamuelover 8 years ago
&gt;&quot;When we originally added asynchronous exceptions to Haskell ... was shortly after Java had removed the equivalent feature, because it was impossible to program with.&quot;<p>&gt;&quot;...if [Haskell wants] to be able to interrupt ... asynchronous exceptions are the only way, because polling would be a side-effect&quot;<p>File under &quot;Indictments against Haskell&quot;. We&#x27;re gonna need a bigger filing cabinet.
评论 #13471746 未加载
评论 #13471349 未加载