Dynamic error pages in Rails 3

In rails 3.2, it’s easier than that: Add this to config/application.rb: config.exceptions_app = self.routes That causes errors to be routed via the router. Then you just add to config/routes.rb: match “/404”, :to => “errors#not_found” I got this info from item #3 on the blog post “My five favorite hidden features in Rails 3.2” by By … Read more

Common programming mistakes in .Net when handling exceptions? [closed]

What are some of the most common mistakes you’ve seen made when handling exceptions? I can think of lots. First read my article on categorization of exceptions into vexing, boneheaded, fatal and exogenous: http://ericlippert.com/2008/09/10/vexing-exceptions/ Some common errors: Failure to handle exogenous exceptions. Failure to handle vexing exceptions. Construction of methods that throw vexing exceptions. Handling … Read more

Encapsulating retries into `with` block

Is it possible to repeat the code within a with statement? No. As pointed out earlier in that mailing list thread, you can reduce a bit of duplication by making the decorator call the passed function: def do_work(): … # This is not ideal! @transaction(retries=3) def _perform_in_transaction(): # Atomic DB statements … # called implicitly … Read more

Catch python ‘ImportError’ if import from source directory [duplicate]

ImportError: No module named foo actually means the module foo.py or package foo/__init__.py could not be found in any of the directories in the search path (sys.path list). Since sys.path usually contains . (the current directory), that’s probably what you meant by being in the source directory. You are in the top-level directory of package … Read more

Unhandled Exception Global Handler for OWIN / Katana?

Try writing a custom middleware and placing it as the first middleware: public class GlobalExceptionMiddleware : OwinMiddleware { public GlobalExceptionMiddleware(OwinMiddleware next) : base(next) {} public override async Task Invoke(IOwinContext context) { try { await Next.Invoke(context); } catch(Exception ex) { // your handling logic } } } Place it as the first middleware: public class Startup … Read more

Close resource quietly using try-with-resources

I found this answered on the coin-dev mailing list: http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001503.html 5. Some failures of the close method can be safely ignored (e.g., closing a file that was open for read). Does the construct provide for this? No. While this functionality seems attractive, it is not clear that it’s worth the added complexity. As a practical … Read more