7 utilisateurs inconnus

 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet :

Exception Handling C#

 
n°43892
chappy83
_+_+_+_
Posté le 10-05-2006 à 15:51:25  profilanswer
 

J'ai un probléme avec les exception suivante:
 
 

Code :
  1. private string getSSID()
  2.     {
  3.         string ssid = null;
  4.         try
  5.         {
  6.             //int index = User.Identity.Name.IndexOf(@"\" );
  7.             //ssid = User.Identity.Name.Substring(++index);
  8.             if (ssid == null || ssid == string.Empty)
  9.             {
  10.                 //throw new SsidException("You are not authenticaded" );
  11.                 throw new SsidException("You are not authenticaded" );
  12.             }
  13.         }
  14.         catch (SsidException ssidex)
  15.         {
  16.             StringBuilder message = new System.Text.StringBuilder();
  17.             MultiView1.SetActiveView(View3);
  18.             message.AppendFormat("#{0}", ssidex.Message);
  19.             lbDSIDError.Text = message.ToString();
  20.             //return null;
  21.         }
  22.         return ssid;
  23.  
  24.     }


 

Code :
  1. private Employee_R_C GetEmployee(string currentUser)
  2.     {
  3.         try
  4.         {
  5.             Employee_R_RC obj = Employee_R_RC.GetEmployee_R_RC(currentUser);
  6.             Employee_R_C objChild = obj[0];
  7.             return objChild;
  8.         }
  9.         catch (SsidException nrex)
  10.         {
  11.             StringBuilder message = new System.Text.StringBuilder();
  12.             MultiView1.SetActiveView(View3);
  13.             message.AppendFormat("#{0}", nrex.Message);
  14.             lbDSIDError.Text = message.ToString();
  15.             return null;
  16.         }
  17.         catch (Csla.DataPortalException dpex)
  18.         {
  19.             StringBuilder message = new System.Text.StringBuilder();
  20.             MultiView1.SetActiveView(View3);
  21.             message.AppendFormat("##{0} - {1}", dpex.Message, currentUser);
  22.             lbDSIDError.Text = message.ToString();
  23.             return null;
  24.         }
  25.         catch (ArgumentOutOfRangeException ex)
  26.         {
  27.             StringBuilder message = new System.Text.StringBuilder();
  28.             MultiView1.SetActiveView(View3);
  29.             message.AppendFormat("###{0} - {1}", ex.Message, currentUser);
  30.             lbDSIDError.Text = message.ToString();
  31.             return null;
  32.         }
  33.         catch (Exception nrex)
  34.         {
  35.             StringBuilder message = new System.Text.StringBuilder();
  36.             MultiView1.SetActiveView(View3);
  37.             message.AppendFormat("####{0} - {1}", nrex.Message, currentUser);
  38.             lbDSIDError.Text = message.ToString();
  39.             return null;
  40.         }
  41.        
  42.     }


 

Code :
  1. public class SsidException : Exception
  2.     {
  3.         public SsidException(string message):base(message)
  4.         {
  5.         }
  6.     }


 
Moi qui pensait que mon SsidException soit trigé je me tropme c'est toujours le dataportal excpetion, c'est normal. Mia normalement si je trow mon exception et que dans le cathc je le récetionne, pourque l'application ne s'arette pas et rentre dans GetEmployee ???
 

Code :
  1. String SSID = getSSID();
  2. Employee_R_C obj = GetEmployee(SSID);


 

n°43893
Ashe
reenignE esreveR
Posté le 10-05-2006 à 16:04:57  profilanswer
 

Pourquoi elle s'arreterait si tu le catch?
Si tu veux "voir" l'exception mais pas la gerer, tu fais un rethrow :spamafote:


---------------
Globe trotter/SDF - Namur, Belgique
Joy, beautiful spark of the gods, Daughter of Elysium, We enter fire imbibed, Heavenly, thy sanctuary.
Trombi Matbe
n°43894
cruciforme
Artiste incompris
Posté le 10-05-2006 à 16:05:53  profilanswer
 

Jamais fait de C# mais on dirait que quand tu catches ton exception, t'en fais pas grand chose et tu fait quand même un return du ssid :??:
 
bordel  [:cruciforme:1]


Message édité par cruciforme le 10-05-2006 à 16:09:56

---------------
Avec un grand C.. Membre du Club des Nostalgiques d'EUROSPORT| Les recettes de ma copine - RTBF, je t'aime..

Aller à :
Ajouter une réponse