Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Handling 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 way we handle situations like this in many modern programming languages is through excpetions - where a keyword such as try is used to indicate a block of code that may potentially have a problem, and then we use catch or rescue to tell it what to do if something goes wrong.

Exceptions are blocks, and although you may not think so at first the scope (size) of block is every bit as important as the scope of an if or while block.

Sometimes, exceptions will be processed in there entirety by the function / method in which the problem occurs, but at other times you'll want to throw the excpetion back up to the calling level; in that case, you'll need to put a try block in the calling code too. There's a new example of this (in Ruby) on our web site from today's Ruby Programming Course ... and the example is [here]. We have an example showing how it's coded in Python [here], and one from C++ [here}. We've got examples of the format of exceptions in Java on our site too - see [here].

(written 2010-02-03)

 
Associated topics are indexed under
R111 - Ruby - Exceptions.
  [3435] Sorta sorting a hash, and what if an exception is NOT thrown - Ruby - (2011-09-12)
  [3433] Exceptions - a fail-safe way of trapping things that may go wrong - (2011-09-11)
  [3260] Ruby - a training example that puts many language elements together to demonstrate the whole - (2011-04-23)
  [3177] Insurance against any errors - Volcanoes and Python - (2011-02-19)
  [2621] Ruby collections and strings - some new examples - (2010-02-03)
  [2620] Direct access to object variable (attributes) in Ruby - (2010-02-02)
  [2615] String to number conversion with error trapping in Ruby - (2010-02-01)
  [1875] What are exceptions - Python based answer - (2008-11-08)

Y109 - Python - Exceptions
  [3441] Pressing ^C in a Python program. Also Progress Bar. - (2011-09-15)
  [2998] Using an exception to initialise a static variable in a Python function / method - (2010-10-13)
  [2994] Python - some common questions answered in code examples - (2010-10-10)
  [2408] Robust user input (exception handling) example in Python - (2009-09-17)
  [2368] Python - fresh examples of all the fundamentals - (2009-08-20)
  [2281] Python - using exceptions to set a fallback - (2009-07-12)
  [2018] UnboundLocalError - Python Message - (2009-01-31)
  [1236] Trying things in Python - (2007-06-18)
  [1042] Nested exceptions in Python - (2007-01-18)
  [381] Exceptions in Python - (2005-07-17)

C236 - C and C based languages - Exceptions
  [3509] Operator Overloading, Exceptions, Pointers, References and Templates in C++ - new examples from our courses - (2011-11-06)
  [3068] Throwing your own exception in C++, and catching it - (2010-11-24)
  [799] The case for exceptions - (2006-07-11)

J712 - Java - Exceptions
  [3048] String handling - from first steps to practical examples - (2010-11-13)
  [3045] After Course Resources - do we publish sample answers. Example from Java Exceptions module. - (2010-11-13)
  [2862] Fail Safe Error Handling in Java via Exceptions - (2010-07-09)
  [2420] Exceptions in Java - why and how - (2009-09-24)
  [1066] Final, Finally and Finalize - three special words in Java - (2007-02-05)


Back to
Ruby collections and strings - some new examples
Previous and next
or
Horse's mouth home
Forward to
Object Oriented Ruby - new examples
Some other Articles
On Malachite Green
Both feet on the same pavement
Skyline and looking up in London
Object Oriented Ruby - new examples
Handling unusual and error conditions - exceptions
Passing code to procedures and yield in Ruby
What are Ruby Symbols?
Comparing floating point numbers - a word of caution and a solution
3603 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.net/mouth/2622_Han ... tions.html • PAGE BUILT: Fri Feb 3 14:16:04 2012 • BUILD SYSTEM: wizard