Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"06-07-10 - Exceptions"

3 Comments -

1 – 3 of 3
Blogger won3d said...

I think the push/pop style is bad when you have I-cache pressure. This is somewhat mitigated if you have some kind of profile-guided optimization that is doing hot/cold code layout optimizations, but catch() {} is a pretty strong static signal that what transpires is going to be rare, enough that the much slower table-based approach (which is much nicer on the hot instruction stream compared to the push/pops) ends up being an optimization.

There is another issue: your error handling can be done non-locally. You can have code that throws deep in your stack, and you don't have to write code to marshal that error to the handler. That's one way where error-handling with tables ends up being more compact (and therefore, optimistically faster) than the push/pop style.

June 7, 2010 at 3:34 PM

Blogger cbloom said...

Oh yeah, you are correct on all counts, I didn't mean to imply that I thought the push/pop method was okay.

In some bizarro app where exceptions were thrown more often than not, it might be good, but in the normal case where exceptions are very very rare, the data driven method is clearly better.

So IMO it's a good thing they've done to build that style it into x64.

June 7, 2010 at 4:31 PM

Blogger ryg said...

"That is, it's close to the necessary amount of code and time that you have to commit if you actually want to catch all errors and be able to handle them. The way we write more efficient code is simply by not catching all errors (or not being able to continue or shut down cleanly from them). That is we decide that certain types of errors will just crash the app."
I disagree.

"Cleanup stack"-based unwinding incurs a cost on every single function, which means it's equivalent to checking for error conditions in every single function. That is a very bad way of implementing error handling; a method that works much better is to just remember that an error occurred, but substitute
valid data as soon as possible.

That is, separate "tactical" error handling (which just needs to make sure your program ends up in a safe and consistent state) from "strategical" error handling (which is usually at a pretty high level in an app and might involve user interaction), and try to keep most intermediate layers unaware of both.

I consider this good practice in general, not least because immediately escalating error conditions not only makes for hard to understand control flow, but also a bad user experience. Take broken P4 connections, copies of large directories, things like that. Asking me on every single problem is just poor design, but it reflects the underlying model of the application reacting to every error code. Unless there's no way you can sensibly go on, just make a list of things that went wrong and show it to me at the end. That's not just a better user experience, it also tends to be quite easy if it's designed in from the beginning.

June 7, 2010 at 9:23 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.