Difference between revisions of "System Architecture"

From Heureka Wiki
Jump to navigation Jump to search
Line 138: Line 138:
  
 
=== Error Handling ===
 
=== Error Handling ===
När någon typ av fel upptäcks ska ett exception kastas. Inbyggda exceptions ska användas om de passar (till exempel ArgumentException, ArgumentNullException och InvalidOperationException). I annat fall används egna exceptions som ska ärva från ApplicationException.
+
 
Man bör undvika att kod är beroende av exceptions i det normala flödet. Ska man till exempel validera om en sträng innehåller ett giltigt nummer ska man använda int.TryParse(), inte int.Parse() eftersom den sistnämnda ger ett exception om strängen inte är numerisk.
+
When an error is discovered an exception is thrown. Built-in exceptions can be used if appropriate, such as <tt>ArgumentException</tt>, <tt>ArgumentNullException</tt>, and <tt>InvalidOperationException</tt>. In other cases Heureka specific exceptions, inheriting from <tt>ApplicationException</tt>, are used
Behöver man fånga exceptions för att göra någon speciell återhämtning ska man bara fånga det specifika exception man vill återhämta sig från.
+
 
I användargränssnittet bör det finnas exception-hanterare som fångar alla fel från anropad kod och visar lämpligt felmeddelande till användaren. Använd Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog för att visa felmeddelandet.
+
Code that depends on exceptions in the normal flow should be avoided. For instance, if a string should be checked for a valid number it is better to use
Förklaringarna i felmeddelandena bör vara ganska kortfattade. Behövs en längre förklaring, ange HelpLink i det exception som kastas.
+
<tt>int.TryParse()</tt> than <tt>int.Parse()</tt> as the latter throws an exception of the string not is numeric. When designing classes, consider implementing similar methods allowing clients to determine beforehand if an operation is valid or not.
 +
 
 +
Exceptions should only be caught if they are to be handled, and only those exceptions that are relevant should be caught. Do not just catch and re-throw exceptions. This leads to poor performance and also destroys the call stack of the exception.
 +
 
 +
In the user interface there must be an exception handler for all code that might throw exceptions. That code should show an error message to the user if an exception is caught. Use <tt>Slu.Heureka.BaseLayer.HeurekaForms.ErrorDialog</tt> to show error messages.
 +
 
 +
The exception message should be brief. If a longer description is needed, set the <tt>HelpLink</tt> for the exception.
 +
 
 
=== Kommandon ===
 
=== Kommandon ===
 
Design-mönstret Command används för att kapsla in åtgärder användaren utför i egna objekt.
 
Design-mönstret Command används för att kapsla in åtgärder användaren utför i egna objekt.

Revision as of 14:39, 20 May 2010