Question: We have a whole bunch of websites with very similar web.config files.

Can you centralise the duplicate configs in 1 config file before the root directory of each website? Or is the only option machine.config?

We are looking to centralise an assembly reference in the GAC.

Structure:

* Containing Directory
	+ Website 1 Directory
	+ Website 2 Directory
	+ Website 3 Directory
	+ Web.Config File for all above sites

Answer: 
The content inside your `try` block is the interesting stuff, so that should be in functions. Then just select which function you want, and call it, wrapped by your exceptions. You could even write the exception code as a function, and pass the selected function to this as an argument. e.g.

```
def foo():
    num=random.random()
    if num>0.5: print 'OK'
    elif num>0.25: raise NameError('Too Small')
    else: raise KeyboardInterrupt

def bar():
    num=random.random()
    if num>0.8: print 'OK'
    elif num>0.6: raise NameError('Too Small')
    else: raise KeyboardInterrupt

def try_numerics(f):
    try:
        f()
    except NameError:
        print "%s had a NameError" % sys._getframe().f_code.co_name
    except:
        print "%s had a different Error" % sys._getframe().f_code.co_name

# In your main code...
if (need_to_run_foo):
    try_numerics(foo)
elif (need_to_run_bar):
    try_numerics(bar)

```
If those are your actual functions it would be easy to generalize them.

You could create one general function

```
def general(bottom_num, top_num):
  num=random.random()
  try:
    if num>top_num: print 'OK'
    elif num>bottom_num: raise NameError('Too Small')
    else: raise KeyboardInterrupt
  except NameError:
    print "%s had a NameError" % sys._getframe().f_code.co_name
  except:
    print "%s had a different Error" % sys._getframe().f_code.co_name

```

this would keep your code from repeating and address the try: except: issue