Stayvoid wrote:
Indeed. Every exception should be caught, so raising one in the main code is 
not good practice.
Could you tell a little bit more?
(I haven't read the chapter about the exceptions yet.)

Normally, you handle exceptions in this way:

fname = 'file.txt'
try:
  f = open(fname, 'r')
except:
  # Catching all exceptions.
  print >> sys.stderr, 'Unable to open %s.' % fname

When you raise an exception yourself, it should be caught further on so you can handle it elegantly. If you don't then it gets handled by the default exception handler, which just blurts out the execution stack.

def foo(bar):
  if bar < 0:
    raise Exception('FAIL!')

try:
  foo(1)
except:
  print >> sys.stderr, 'Something failed.'

_______________________________________________
gNewSense-dev mailing list
gNewSense-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/gnewsense-dev

Reply via email to