Posted by cloughie (cloughie), 19 December 2007In 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 :
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
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:
if line.startswith(EDW_prefix) :
#print 'starts with @@'
new_line = line.replace('.sql','-prod.sql')
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 ?
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho