| |||
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.
| |||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |