Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
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','','O') + outdir_extention

       fh = open(open_file+'.sql',"r")
       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                            



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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho