What to do with caught exception

When the WCF service is disabled, I will catch this exception like this.

   public List<ProjektyEntity> GetProjekty()
   {
      try
      {
         return this.channel.GetProjekty();
       }
       catch (EndpointNotFoundException exception)
       {
          //what to do at this point ?
       }
    }

But I do not know what to do in the catch block. I can only return an object of the type List<ProjektyEntity>I would like to write a message to the user, something like "Service is disabled" My Presentation Level is ASP.NET MVC. Is there any strategy for such situations?

+5
source share
7 answers

There is a simple rule: if you do not know how to handle the exception, do not understand it.

, , , , . , , .

throw e; , . throw; , , . . , , , finally.

, , - , , , . .

, , (, ), , InnerException, :

try
{
    foo(bar);
}
catch (Exception e)
{
    throw new FooException("Foo failed for " + bar.ToString(), e);
}

, . - , InnerException. . .

+15

. , , .

  • null. , . , , , .
  • , . (.. / /etc )
  • ServiceNotAvailableException , .
  • . , , .
+8

, ; .

+4

:

1) , ( )

2) , , ,

catch (EndpointNotFoundException exception) 
{ 
   CleanUpMyOwnState();
   throw;                  // Pass the exception on the to the caller to handle
} 

3) ( ):

catch (EndpointNotFoundException exception) 
{ 
   CleanUpMyOwnState();
   throw new InvalidOperationException("Endpoint was not found", exception);
} 

4) , (, null), , ( )

5) . , - .

+4

An exception is not intended to be caught and handled in this context. It needs to be processed at a much higher level, having access to any console as a whole.

The best you can do here is simply to register the exception with the necessary details and restore correctly.

+2
source

Create an exception object with sufficient debugging granularity and call the call method

+1
source
 public List<ProjektyEntity> GetProjekty()
   {
      try
      {
         return this.channel.GetProjekty();
       }
       catch (EndpointNotFoundException exception)
       {
          'Write here Some Clean Up Codes
          ' Log it somewhere on your server so that you can fix the error

       }
    }
0
source

All Articles