Application Architecture Design -- Exception Management

  • Thread starter Thread starter Homa
  • Start date Start date
H

Homa

Hi All,

The question I'm asking applies to any general application design. I'm
just using the project I'm working on as an example.

I'm writing an application with a C# wrapper of DDEML, and I created
an exception dmlException for the DDEML
errors. Currently I'm placing the
[i:ec17216d38]dmlException[/i:ec17216d38] and
[i:ec17216d38]dmlModule[/i:ec17216d38] (the wrapper) together in a
project called ddeml.

But now I'm thinking of centralize the exceptions to one location, say
[b:ec17216d38]myAppException[/b:ec17216d38] project so that other
part of the application can use all application exception by adding
only one reference. But in the
[i:ec17216d38]dmlException[/i:ec17216d38], one of the constructor
takes an Enum [i:ec17216d38]DMLERR[/i:ec17216d38] argument with is
defined within the [i:ec17216d38]dmlModule[/i:ec17216d38]. This would
cause a circular reference. How should I solve this?

I'm thinking of centralize the exceptions to one project because I
don't feel like the UI Component need a reference to the
[i:ec17216d38]dmlModule[/i:ec17216d38] or other low-level modules.

Am I reasonable in doing these?

Thanks for concern,
Homa Wong
 
If you want the exception to have a custom field that is itself a custom
type, then you should define the custom type in the same assembly as the
custom exception. The same principle applies to any special types you use as
arguments to its methods. Otherwise you will need to ensure that two
assemblies (or perhaps more) are available to code that wants to consume the
exception so that all references to it can be satisfied.
 
Thanks. As the custom type is related to error reporting, it
justisfies placing in the exception module.

One step up the question. If the application uses several different
modules and each of the modules has its own exceptions, how do I
centralize them?

Make a exception module and use extern to reference all these
different exceptions?

Homa Wong
 
The first issue to address is if you really need to use a custom exception.
You normally should only define one if you have a scenario in which code
that calls the module that throws the custom exception can programmatically
recover from the exception. In other words, if the module throws a
YouCantDoThatException, it expects the calling code to take some specific
action so that the next time it calls it the operation might succeed. If all
the custom exception does is convey error information then you are usually
better off using a predefined exception and providing a comprehensive error
message.

When using custom exceptions you need to ensure that all code that uses them
have access to the assembly that defines them. If a module throws an
exception built with version 1.1 of the assembly it may not be able to be
deserialized by a component that was built using version 1.0 of the assembly
that defined the exception. This can become problematic in a distributed
system that evolves independently from other parts of the system.

If you put the definition of the exceptions into a single module then all
the code that uses them will access the same assembly. This may be a good
approach but it's hard to tell without really knowing what the overall
architecture of your system is and what the expected upgrade path will be.


Homa said:
Thanks. As the custom type is related to error reporting, it
justisfies placing in the exception module.

One step up the question. If the application uses several different
modules and each of the modules has its own exceptions, how do I
centralize them?

Make a exception module and use extern to reference all these
different exceptions?

Homa Wong



----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption
=---
 
Back
Top