Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Ruby module R111
Exercises, examples and other material relating to training module R111. This topic is presented on public courses Learning to program in Ruby, Ruby Programming

You can check for some, but not all, errors. It's sometimes necessary (and often preferable even if not necessary) to write clean code that assumes correct operation, and provide rescue blocks telling Ruby what to do in the event of a failure.
Related technical and longer articles
errors v exceptions

Articles and tips on this subjectupdated
4675Exceptions in Ruby - throwing, catching and using
It's far better to use exceptions to trap run time irregularities than to try to forecast all possible errors, as exceptions form a sort of safety net. From today's Ruby Course, [here] is an example where the user is prompted to enter an integer, and I deliberately use the Integer function rather than ...
4008Reading and checking user inputs - first lessons - Ruby
Early programming exercises on a "learning to program in Xxxx" course involve asking the user to enter some pieces of data (usually numbers), doing a calculation using those numbers, and printing out a result. For that's a quite common requirement for a simple program - and this is the first realistic ...
3435Sorta sorting a hash, and what if an exception is NOT thrown - Ruby
Some gems from last week ... 1. Ruby's begin and rescue clauses allow you to catch anything exceptional that could derail your program. But did you know that you can also add an else clause to be run only in the event of there being no exception? There's an example from last week's Ruby course which ...
3433Exceptions - a fail-safe way of trapping things that may go wrong
As part of a previous post, I was looking at the "Internal Server Errors" logged on our web server over the past 3 months ... and I found one coming from a Python / CGI demonstration which I wrote and uploaded for a delegate a couple of months back. Internal server error 500 (by default on Apache httpd) ...
3260Ruby - a training example that puts many language elements together to demonstrate the whole
Towards the end of our programming language training courses, we pull together all the various strands into a worked example that shows how they go together. I've just posted such an example from last week's Ruby Programming Course ... [here]. Let's have a look at some of the things in the example ...
3177Insurance against any errors - Volcanoes and Python
Have you heard of people who have taken out insurance, only do discover that they're not covered for some eventuality - "but the list of circumstances doesn't include your flight being canceled because the plane couldn't fly through volcanic ash" is a story that many people heard, with an irony that ...
2622Handling unusual and error conditions - exceptions
"I can't answer that question in the way you expect" ... that's something that may be said to you occasionally - you ask someone what suit a playing card is that they're holding and they cannot tell you because it is a joker, or you ask what number is written on a piece of paper when the paper is blank. The ...
2621Ruby collections and strings - some new examples
From yesterday's Ruby course - a whole set of new examples on Ruby collections - arrays (which are ordered lists) and hashes (which are unordered). In other words, you look somethng up in an array by its position number, whereas you look something up in a hash based on its unique key, and the way it's ...
2620Direct access to object variable (attributes) in Ruby
Rather than writing getters and setters, in many Object Oriented languages you can access the variables within an object directly. That can be dangerous for code flexibility for the future, as it means that you're removing the possibility of interspersing code. However, it can be very convenient. In ...
2615String to number conversion with error trapping in Ruby
You've read in a string of text in Ruby - perhaps the user's input, or perhaps from a file. You know that string shoould contain a number - so you use the to_i method to do the conversion. But there's a problem - if the string doesn't start with a number, it won't convert correctly - it will just ...
1875What are exceptions - Python based answer
How do you check for run time errors in your program? You'll include tests with if statements in almost every program you write, to ensure that user entered data is reasonable / as you would expect ... but you will also need to do more that that. You'll need to check whether a system function has run ...
Examples from our training material
bmi.rb   BMI (Body Mass Index) calculator
catcher   Converting String to Integer and handling errors
chq   catching exceptions - file handling
except   raisieng and catching exceptions between methods
fsta.rb   File Reporter - assumes all is OK
fstb.rb   File Reporter - handle problems with open
fstc.rb   File Reporter - handle multiple problems and re prompt
mc   Catching user errors - a short demonstration
mighty.rb   Passing exceptions back to calling code
mycode   input a number from user, deal with errors / exceptions
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from [here].
Topics covered in this module
begin and end (and a mention of BEGIN and END).
Raise and rescue.
Throw and catch.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Ruby, Lua, Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/R111.html • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb