made examples callable and added the error handling to a function
Merge pull request #465 from dcapwell/exampleRewrite

made examples callable and added the error handling to a function