Mountain of exception throwers

During software maintainance, you get error messages you need to fix. Being sensitive and take note of some of this, gives experience for your next development project.

When developing code that opens a file, for example, you should throw an exception when the code fails to work. Not any kind of exception, but one that describes what went wrong.

Your MyappException should extend Exception. You can even have a whole hierarchy of exception classes to handle all situations correctly. In practice though, you dont go for just one top level exception. You want to have two kinds of top level application exception classes; MyappWarningException and MyappErrorException. Both extend Exception.

When running applications operationally, it is important to differentiate on errors and warnings for each requires different kinds of action. In my situation, warnings are logged to file and not shown to users, while errors have a user friendly message sent to users as well as logging.

We use Log4j (with Apache Commons Logging) and set different logging levels for errors and warnings. Log4j has the advantage that it is easy to set up in property files that messages of a specific level should be emailed. It also handles the logging to file business. As well as not logging in test runs, thanks to making different test/release builds with Apache Ant.

Kommentarer

Populære innlegg fra denne bloggen

5 generations of computer languages

DOJO kamptyper [forbedre egen kompetanse]

Generations of text formats