Help on Exception Handling ????

  • Thread starter Thread starter Serge Calderara
  • Start date Start date
S

Serge Calderara

Dear all,

I am buiding a quite huge application which is devided in
quite many small functionnality that we will call modules
here to simplify.

I need to implement my exception handling routine that
need to be language dependent. I mean that all error
should be able to depend on selected language. For that I
need some good advide on what is the best way according to
your experience to handle it:

1- is it better to get an exception handling for each
modules?

2 - is it better to have a module itself called
myException that every modules gets referenced?

3 - I might need to add my own custom error message how
to do ?

Thanks for your advise
Regards
Serge
 
Can't tell you which is the best way... but I've gone for an error class
that that has a static function AddError, passing in severity, error code,
error message and from which module \ function.

This gives me the flexibility later, if I decide to actually log errors,
give different messages on severity types etc...

Hope that helps.

rollasoc
 
Serge said:
Dear all,

I am buiding a quite huge application which is devided in
quite many small functionnality that we will call modules
here to simplify.

I need to implement my exception handling routine that
need to be language dependent. I mean that all error
should be able to depend on selected language. For that I
need some good advide on what is the best way according to
your experience to handle it:

For "depend on selected language" I assume you mean a locale (or culture)
language rather than a programming language. The internationalization story
in .NET is good in some respects by bad in others. The bad side is that it
puts the responsibility of internationalization on the developer _when the
text is created_ rather than on the code that will display the text. (If you
want to internationalize a form, this a good thing; but if you want to
internationalize an event log message, it is a bad thing because the event
log can be read by another machine in another locale.)

The good part is that you create multiple resource library assemblies (DLLs
called satellite assemblies), one for each culture. You put the localized
text messages in the assembly and associate each with an ID. You then create
a ResourceManager object which will automatically determine the culture that
the current thread uses and load the appropriate satellite. When you ask it
for a string by passing the ID, the appropriate localized string is
returned. If the code is run on a culture for which a satellite is not
available there is a fallback mechanism. For example, if you run on UK
English (en-UK) and that satellite is not available the ResourceManager will
look for generic English (en) and if that satellite is not available it will
look for neutral resources. Neutral resources are embedded as part of the
application assembly. It is important to provide neutral resources beause it
means that there will always be a message - even if it is not in the
language of the reader!
1- is it better to get an exception handling for each
modules?

Are you talking about .NET modules? In which case the answer is no. I
suspect you are talking about assemblies (library and process assemblies).
..NET localization is application based: satellite assembluies are associated
with an application.
2 - is it better to have a module itself called
myException that every modules gets referenced?
No.

3 - I might need to add my own custom error message how
to do ?

hmmm, I am not sure if you understand .NET exceptions. Each exception has a
Message property that contains details of the exception and may have other
properties. Its better to localize the exception message when you create the
exception:

if (param1 == 0)
{
Assembly assem = Assembly.GetExecutingAssembly();
ResourceManager rm = new ResourceManager("MyExceptionMessages", assem);
String msg = rm.GetString("ParamIsZero");
throw new ArgumentException(msg, "param1");
}

This means that if you catch the exception in other code and log (or
display) the exception you do not have to localize the message.

Richard
 
Back
Top