Why is it better to throw an exception rather than return an error code?

I’ve written about this at length: Exceptions vs. status returns, but briefly: Exceptions leaves your code clean of all the checks necessary when testing status returns on every call, Exceptions let you use the return value of functions for actual values, Exceptions can carry more information than a status return can, Most importantly: exceptions can’t … Read more

Exception: Concurrent modification during iteration: Instance(length:17) of ‘_GrowableList’

This error means that you are adding or removing objects from a collection during iteration. This is not allowed since adding or removing items will change the collection size and mess up subsequent iteration. The error is likely from one of these lines which you haven’t posted the source for: s.collisionResponse(e); e.collision(s); s.collision(e); I assume … Read more

Can I get detailed exception stacktrace in PowerShell?

There is a function up on the PowerShell Team blog called Resolve-Error which will get you all kinds of details Note that $error is an array of all the errors you have encountered in your PSSession. This function will give you details on the last error you encountered. function Resolve-Error ($ErrorRecord=$Error[0]) { $ErrorRecord | Format-List … Read more

Could not load file or assembly System.Net.Http.Primitives. Located assembly’s manifest definition does not match the assembly reference

I ran into the same issue with the Google API’s. The main issue here is if you install the Microsoft Http Client Libraries it puts in your project an updated version of the System.Net.Http.Primitives DLL. The web.config assumes you are still using the default version of 1.5. There are two things that need to happen … Read more

Spock – Testing Exceptions with Data Tables

The recommended solution is to have two methods: one that tests the good cases, and another that tests the bad cases. Then both methods can make use of data tables. Example: class SomeSpec extends Specification { class User { String userName } def ‘validate valid user'() { when: validateUser(user) then: noExceptionThrown() where: user << [ … Read more

Catching panics in Golang

A panicking program can recover with the builtin recover() function: The recover function allows a program to manage behavior of a panicking goroutine. Suppose a function G defers a function D that calls recover and a panic occurs in a function on the same goroutine in which G is executing. When the running of deferred … Read more

ASP.NET Web API: Non-descriptive 500 Internal Server Error

You can try adding: GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; to your Application_Start() in the Global.asax. This solution works for many of the common errors. If, however, you aren’t getting satisfactory information you should consider writing an l Exception Filter and registering it globally. This article should get you started. The core of what you need is to … Read more