Using bool (return Type) to handle exceptions or exceptions for the client?

I am trying to find a better way to handle exceptions, I have several layers for my application and started using the return type BOOL, i.e. if it fails, return False and if it succeeds in returning True ..

This works great in methods like SaveMyRecord (somerecord); since I pass in the values ​​and do not require anything returned, so I can use the return type bool to indicate whether it is successful or not.

But then it seemed to me that things like GetMyRecord () did indeed return the IQueryable type, so I cannot use bool to tell me if it failed or not.

The fact is that I process my errors a lot when they happen with try and catch, and therefore do not want the client to get an exception.

Perhaps there is a better way, so I thought about using OUT parameters, but that means I need to change the signature of all methods and add additional parameters ..

Maybe I should pass the exception back to the CLIENT and handle it there?

Are there any standards or documents to use best practices?

+5
source share
6 answers

Bubble up CLIENT . . , , , , , -.

, , , . , , "" , , , " ex"

, SO.

+10

, , , Exception Shielding.

: - (ASMX WCF) , - , .

+5

, . .

+4

, , . ( ) (2- .), try-parse.

( ), :

  • / .
  • . , ? .

, , , - . , , , , , (, ).

+2

!

. , . : ( , ).

+1

, MS - ComputeSomething(), 'int', TryComputingSomething(), Boolean. , , pass-in True; "" , False. , .

, . , , , . , , , . , 20-37 , , . , ; .

+1

All Articles