Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#359 closed defect (fixed)

raise Exception(msg) - Python 2.6 upgrade

Reported by: habili Owned by: habili
Priority: normal Milestone:
Component: Appearance and visualisation Version:
Severity: normal Keywords:


If you do:

find <path_to_anuga_src> -name \*.py -exec grep "raise ['a-z]" {} \; | \

grep -v " *#" | grep -v " *'" | grep " *raise"

you will find lots of instances in ANUGA of "raise <string>", which in python 2.6+ is an error:

raise 'test'

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError?: exceptions must be old-style classes or derived from BaseException?, not str

So we should replace these with "raise Exception(msg)". Or some other exception besides Exception.

This is not super-critical. It just means that any of the conditions that attempt to do "raise <string>" will fail without the (hopefully) meaningful message.

It also means that ANUGA test code isn't forcing any of these conditions.

Change History (3)

comment:1 Changed 13 years ago by wilsonr

  • Resolution set to fixed
  • Status changed from new to closed

For all 49 files that showed up when doing:

find $PYTHONPATH/anuga -name \*.py -exec grep "raise ['a-z]" {} \;


raise 'string'


raise Exception('string')


raise Exception, 'string'


raise Exception('string')

comment:2 Changed 13 years ago by wilsonr

The above changes were only made in the anuga directory. No changes were made in the anuga_parallel code because the example find found no instances of incorrect 'raise' usage.

comment:3 Changed 12 years ago by neweyv

There are still hundreds of occurrences of 'raise msg' outside anuga_core. They mostly occur in anuga_work/development/. These instances have not been fixed as they occur in old projects, which are not commonly used. 8 occurences in anuga_trunk/misc/tools/pytools/ were fixed.

Note: See TracTickets for help on using tickets.