Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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 as below, or enter http://melksh.am/nnnn for individual articles
Y109 - Python - Exceptions
  [381] Exceptions in Python - (2005-07-17)
  [1042] Nested exceptions in Python - (2007-01-18)
  [1236] Trying things in Python - (2007-06-18)
  [2018] UnboundLocalError - Python Message - (2009-01-31)
  [2281] Python - using exceptions to set a fallback - (2009-07-12)
  [2368] Python - fresh examples of all the fundamentals - (2009-08-20)
  [2408] Robust user input (exception handling) example in Python - (2009-09-17)
  [2994] Python - some common questions answered in code examples - (2010-10-10)
  [2998] Using an exception to initialise a static variable in a Python function / method - (2010-10-13)
  [3177] Insurance against any errors - Volcanoes and Python - (2011-02-19)
  [3433] Exceptions - a fail-safe way of trapping things that may go wrong - (2011-09-11)
  [3441] Pressing ^C in a Python program. Also Progress Bar. - (2011-09-15)
  [3664] Error checking in a Python program - making your program robust via exceptions - (2012-03-22)
  [3913] How many times ... has this loco headed west through Tenby? - Python exceptions - (2012-11-05)
  [3930] Reporting the full stack trace when you catch a Python exception - (2012-11-22)
  [4029] Exception, Lambda, Generator, Slice, Dict - examples in one Python program - (2013-03-04)
  [4161] Python varables - checking existance, and call by name or by value? - (2013-08-27)
  [4444] Elements of an exception in Python - try, except, else, finally - (2015-02-28)

R111 - Ruby - Exceptions.
  [1875] What are exceptions - Python based answer - (2008-11-08)
  [2615] String to number conversion with error trapping in Ruby - (2010-02-01)
  [2620] Direct access to object variable (attributes) in Ruby - (2010-02-02)
  [2621] Ruby collections and strings - some new examples - (2010-02-03)
  [3260] Ruby - a training example that puts many language elements together to demonstrate the whole - (2011-04-23)
  [3435] Sorta sorting a hash, and what if an exception is NOT thrown - Ruby - (2011-09-12)
  [4008] Reading and checking user inputs - first lessons - Ruby - (2013-02-17)
  [4675] Exceptions in Ruby - throwing, catching and using - (2016-05-17)

J712 - Java - Exceptions
  [1066] Final, Finally and Finalize - three special words in Java - (2007-02-05)
  [2420] Exceptions in Java - why and how - (2009-09-24)
  [2862] Fail Safe Error Handling in Java via Exceptions - (2010-07-09)
  [3045] After Course Resources - do we publish sample answers. Example from Java Exceptions module. - (2010-11-13)
  [3048] String handling - from first steps to practical examples - (2010-11-13)
  [4350] Keyboard reader for Java programming newcomers - (2014-12-12)
  [4396] Java Utility class - flexible replacement for array. Also cacheing in objects and multiple catch clauses example. - (2015-01-16)

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


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
4759 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, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 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., 2021: 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/mouth/2622_Han ... tions.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb