Training, Open Source computer languages

This is page http://www.wellho.net/forum/Programm ... -Ruby/Exception-Handling.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - 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))
Exception Handling

Posted by cloughie (cloughie), 19 December 2007
In Oracle's procedural language PlSql - which is block structured - you can :

* use exisiting Exceptions
* create user defined Exceptions
* apply catch all Exceptions

Either way, when an exception occurs the process looks for the handling of that exception WITHIN that block of code (ignoring all other code within that Block) or, if not handled there, progressively works it way into outer blocks, similarly looking for the handled exception.

The upshot of this is that you don't have to define a whole load of flags in the way that I've done in my Python code :

================================
def construct_EDW_Prodscript(dbreqnr):

   invalid_data = ''

   # invoking file will be written  to the same directory, but with a suffix of '-prod'
   # on the filename

   # set variable to pinpoint the invoking file
   outdir_extention = 'dbreqnr'+str(dbreqnr)+'\EDW_'+str(dbreqnr)

   open_file = get_default_dir('ORA99ET','obtain99ETentries.py','O') + outdir_extention

   try:
       fh = open(open_file+'.sql',"r")
   except:
       err_msg = 'Could not find file '+open_file+' Returning to Menu ...'
       invalid_data = 'true'


   if not invalid_data:

       # open new prod version of invoking file
       fh2 = open(open_file+'-prod.sql',"w")
       
       new_line = ''

       # loop through all lines in invoking file and add a suffix for the called sql scripts,
       # then create new file.
       for line in fh:
           #print line
           if line.startswith(EDW_prefix) :
               #print 'starts with @@'
               new_line = line.replace('.sql','-prod.sql')
               #print 'new_line=',new_line
           else : new_line = line                            
           fh2.write(new_line)

       fh.close()
       fh2.close()
       etc
       etc

================================

As you can see, the boolean attribute 'invalid_data' controls whether subsequent code gets run or not, but sometimes it can get a bit messy.

Is there a way of avoiding using boolean flags and make use of Exception handling instead ?

Best regards,
TNT Dave





This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

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