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

How to implement proper HTTP error handling in .NET MVC 2?

Here’s one technique you could use. Define an ErrorsController which will serve the error pages: public class ErrorsController : Controller { public ActionResult Http404() { Response.StatusCode = 404; return Content(“404”, “text/plain”); } public ActionResult Http500() { Response.StatusCode = 500; return Content(“500”, “text/plain”); } public ActionResult Http403() { Response.StatusCode = 403; return Content(“403”, “text/plain”); } } … Read more

What are “cerr” and “stderr”?

cerr is the C++ stream and stderr is the C file handle, both representing the standard error output. You write to them the same way you write to other streams and file handles: cerr << “Urk!\n”; fprintf (stderr, “Urk!\n”); I’m not sure what you mean by “recover” in this context, the output goes to standard … Read more

How to manually return a Result?

Error is a trait and you want to return a trait object (note the dyn keyword), so you need to implement this trait: use std::error::Error; use std::fmt; #[derive(Debug)] struct MyError(String); impl fmt::Display for MyError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, “There is an error: {}”, self.0) } } impl Error for … Read more

How to handle or avoid a stack overflow in C++

Handling a stack overflow is not the right solution, instead, you must ensure that your program does not overflow the stack. Do not allocate large variables on the stack (where what is “large” depends on the program). Ensure that any recursive algorithm terminates after a known maximum depth. If a recursive algorithm may recurse an … Read more