C# What is best practise for handling Data Errors and Warnings as opposed to Exceptions2019 Community Moderator ElectionWhat is the proper way to re-throw an exception in C#?Best practices for exception management in Java or C#What is the best data type to use for money in C#?Error Handling Should I throw exception? Or handle at the source?Implement Exception Handling in ASP.NET C# ProjectWhat should be the best Exception Handling StrategyWCF data dervices exception handling on client sideInversion of Control and injection of data layer dependencies in the Business LayerBest practice for xml service response error handlingWhat is the best practice of catching exception in this case

Will expression retain the same definition if particle is changed?

Can one live in the U.S. and not use a credit card?

Origin of the word “pushka”

I am the person who abides by rules, but breaks the rules. Who am I?

(Codewars) Linked Lists-Sorted Insert

How do spaceships determine each other's mass in space?

Do black holes violate the conservation of mass?

"If + would" conditional in present perfect tense

Converting from "matrix" data into "coordinate" data

Is it possible to clone a polymorphic object without manually adding overridden clone method into each derived class in C++?

Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

School performs periodic password audits. Is my password compromised?

Was it really inappropriate to write a pull request for the company I interviewed with?

Automaton recognizing ambiguously accepted words of another automaton

Create chunks from an array

Are small insurances worth it?

If nine coins are tossed, what is the probability that the number of heads is even?

Why do we say 'Pairwise Disjoint', rather than 'Disjoint'?

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls

What is better: yes / no radio, or simple checkbox?

What is the purpose of a disclaimer like "this is not legal advice"?

What will happen if my luggage gets delayed?

Why does Central Limit Theorem break down in my simulation?



C# What is best practise for handling Data Errors and Warnings as opposed to Exceptions



2019 Community Moderator ElectionWhat is the proper way to re-throw an exception in C#?Best practices for exception management in Java or C#What is the best data type to use for money in C#?Error Handling Should I throw exception? Or handle at the source?Implement Exception Handling in ASP.NET C# ProjectWhat should be the best Exception Handling StrategyWCF data dervices exception handling on client sideInversion of Control and injection of data layer dependencies in the Business LayerBest practice for xml service response error handlingWhat is the best practice of catching exception in this case










0















We are creating a new .Net Core Library, an application service that resides within a Clean Architecture.



The new service will read new customer details via the RepositoryService layer and Post them via a RestApiService Layer to multiple systems including : CreditCheck system, Billing system etc..



Within the new Application Service we want a consistent way of handling responses from RestAPi service. Response data includes:



- Return values: entities returned by restAPI service 

- Exceptions like an error 500, time outs.. that have bubbled up from the RestAPi.

- Data Errors messages such as Customer already exists, bank details invalid

- Warning messages ... "Processing continues as normal, but order is flagged"


It is the last two that are foxing us, because this is different to the interaction with the Repository layer which has no business logic, so basically returns a success or an exception.



Microsoft and SOLID virtually state that the use of exceptions handling is the way to go , whether it be exceptions, errors or warnings.



But in this scenario not clear how this will work ..



 a. We loose the option of handling and forwarding on the return values. 
We really don't fancy storing all this in the exception message

- Whilst not a show stopper, we fear the code will be more difficult to read than it needs to be.

- Exception handling is expensive,but not worried too much on this score with number of transactions.


We are drawn to some how using FluentValidation or a hybrid version, it will need to work with Logging and RepositoryService as we will need log and decode stuff .



We really don't fancy repeating the RestAPi Service layer approach i.e. handling HTTP exceptions separately, then processing return values which are basically extended entities with Errors Status , Error codes and messages.



We are not expecting the above to be specific to our company. The issue seems to be around handling messages from a 3rd Party Business logic layer , within our Application Service.



So our question is how can we best handle Errors warnings along side data in the application service layer and still have SOLID testable and maintainable code ?










share|improve this question







New contributor




user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    0















    We are creating a new .Net Core Library, an application service that resides within a Clean Architecture.



    The new service will read new customer details via the RepositoryService layer and Post them via a RestApiService Layer to multiple systems including : CreditCheck system, Billing system etc..



    Within the new Application Service we want a consistent way of handling responses from RestAPi service. Response data includes:



    - Return values: entities returned by restAPI service 

    - Exceptions like an error 500, time outs.. that have bubbled up from the RestAPi.

    - Data Errors messages such as Customer already exists, bank details invalid

    - Warning messages ... "Processing continues as normal, but order is flagged"


    It is the last two that are foxing us, because this is different to the interaction with the Repository layer which has no business logic, so basically returns a success or an exception.



    Microsoft and SOLID virtually state that the use of exceptions handling is the way to go , whether it be exceptions, errors or warnings.



    But in this scenario not clear how this will work ..



     a. We loose the option of handling and forwarding on the return values. 
    We really don't fancy storing all this in the exception message

    - Whilst not a show stopper, we fear the code will be more difficult to read than it needs to be.

    - Exception handling is expensive,but not worried too much on this score with number of transactions.


    We are drawn to some how using FluentValidation or a hybrid version, it will need to work with Logging and RepositoryService as we will need log and decode stuff .



    We really don't fancy repeating the RestAPi Service layer approach i.e. handling HTTP exceptions separately, then processing return values which are basically extended entities with Errors Status , Error codes and messages.



    We are not expecting the above to be specific to our company. The issue seems to be around handling messages from a 3rd Party Business logic layer , within our Application Service.



    So our question is how can we best handle Errors warnings along side data in the application service layer and still have SOLID testable and maintainable code ?










    share|improve this question







    New contributor




    user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      We are creating a new .Net Core Library, an application service that resides within a Clean Architecture.



      The new service will read new customer details via the RepositoryService layer and Post them via a RestApiService Layer to multiple systems including : CreditCheck system, Billing system etc..



      Within the new Application Service we want a consistent way of handling responses from RestAPi service. Response data includes:



      - Return values: entities returned by restAPI service 

      - Exceptions like an error 500, time outs.. that have bubbled up from the RestAPi.

      - Data Errors messages such as Customer already exists, bank details invalid

      - Warning messages ... "Processing continues as normal, but order is flagged"


      It is the last two that are foxing us, because this is different to the interaction with the Repository layer which has no business logic, so basically returns a success or an exception.



      Microsoft and SOLID virtually state that the use of exceptions handling is the way to go , whether it be exceptions, errors or warnings.



      But in this scenario not clear how this will work ..



       a. We loose the option of handling and forwarding on the return values. 
      We really don't fancy storing all this in the exception message

      - Whilst not a show stopper, we fear the code will be more difficult to read than it needs to be.

      - Exception handling is expensive,but not worried too much on this score with number of transactions.


      We are drawn to some how using FluentValidation or a hybrid version, it will need to work with Logging and RepositoryService as we will need log and decode stuff .



      We really don't fancy repeating the RestAPi Service layer approach i.e. handling HTTP exceptions separately, then processing return values which are basically extended entities with Errors Status , Error codes and messages.



      We are not expecting the above to be specific to our company. The issue seems to be around handling messages from a 3rd Party Business logic layer , within our Application Service.



      So our question is how can we best handle Errors warnings along side data in the application service layer and still have SOLID testable and maintainable code ?










      share|improve this question







      New contributor




      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      We are creating a new .Net Core Library, an application service that resides within a Clean Architecture.



      The new service will read new customer details via the RepositoryService layer and Post them via a RestApiService Layer to multiple systems including : CreditCheck system, Billing system etc..



      Within the new Application Service we want a consistent way of handling responses from RestAPi service. Response data includes:



      - Return values: entities returned by restAPI service 

      - Exceptions like an error 500, time outs.. that have bubbled up from the RestAPi.

      - Data Errors messages such as Customer already exists, bank details invalid

      - Warning messages ... "Processing continues as normal, but order is flagged"


      It is the last two that are foxing us, because this is different to the interaction with the Repository layer which has no business logic, so basically returns a success or an exception.



      Microsoft and SOLID virtually state that the use of exceptions handling is the way to go , whether it be exceptions, errors or warnings.



      But in this scenario not clear how this will work ..



       a. We loose the option of handling and forwarding on the return values. 
      We really don't fancy storing all this in the exception message

      - Whilst not a show stopper, we fear the code will be more difficult to read than it needs to be.

      - Exception handling is expensive,but not worried too much on this score with number of transactions.


      We are drawn to some how using FluentValidation or a hybrid version, it will need to work with Logging and RepositoryService as we will need log and decode stuff .



      We really don't fancy repeating the RestAPi Service layer approach i.e. handling HTTP exceptions separately, then processing return values which are basically extended entities with Errors Status , Error codes and messages.



      We are not expecting the above to be specific to our company. The issue seems to be around handling messages from a 3rd Party Business logic layer , within our Application Service.



      So our question is how can we best handle Errors warnings along side data in the application service layer and still have SOLID testable and maintainable code ?







      c# asp.net-core inversion-of-control nuget-package onion-architecture






      share|improve this question







      New contributor




      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Mar 6 at 23:11









      user3720465user3720465

      32




      32




      New contributor




      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user3720465 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Microsoft and SOLID are right.



          The correct way to go are Exceptions as per standard practices (and c#), independently of another considerations, like performance for instance.



          Generally speaking there are two different types of "Errors", technical, and business logic related.



          Failing to Connect to a DB, receiving a 500 from a REST Service, etc... are technical, and as they could be transient you can try to recover from this situation, sometimes without success, what finally causes the Business Orchestration/Process failure.



          Business Logic errors, like 'Customer already exists', 'Bank details invalid','Input data is not in the valid format' are non-transient, and determined solely by Business Rules (some implicit, other explicit) and will stop stop your process as well without possibility to recover, simply because something is not in the proper/expected state.



          There is a reason we use Exceptions (as technical artifacts) and is to handle these hard-stops 'properly'.



          Every time you throw an Exception the application traverse back the stack up to the first available Exception Handler able to handle such Exception, returning the control to you and to a known location where something will happen (telemetry, rethrow, show a dialog to the user...)



          Any mechanism trying to substitute this propagation (Error) must rely, for instance, on hijacking the return value of the methods to provide back a status, or forcibly include an out parameter to all your methods signatures, which will have awful collateral effects in your implementation.



          Yes, sometimes your current design look 'too flat' that you are tempted to hijack the return value here and there, creating a highly coupled component, but you never can tell how the system complexity will grow, meaning that at some point you will extend your system with additional layers, and most likely the 'substituting mechanism' approach will not fit , and you are forced to support them, the regular way and the imaginative one.



          So, trying to implement a custom solution will create a tightly-coupled technical requirement that must be supported all across the board, what in architecture terms is simply 'not good' (not a good practice)



          IF any Service you are consuming is not able to produce a meaningful 'error' information, well structured, then, the Service is not well designed, and the problem flips to the Client side (Talking in SOA terms).



          The only 'most correct' solution left to not introduce chaos in your Client is by creating a Proxy to the Service RESPECTING the rules required by your implementation approach.



          My recommendation about Error Handling is very simple, stick to the rules that are well know and have been in place for decades and do not try workaround this by yourself, or you are going to face too many issues, create a Proxy for each service and integrate them properly in your code base (unit testing and such)



          In regards to warnings, there is no recommendation from anybody to handle this by using Exceptions, those 'warnings' in your question is a normal output when interacting to the Service/a logical state supported by the Business Logic, thus, the place to handle this state is in the Data Contract coming back from the Service, again, if the Service is so horribly designed that is replying you with just a text string containing the word 'warning', and you are forced to parse this string to notice the situation, then your Proxy to the Service should check for it and provide a meaningful and well structured output to the Client.






          share|improve this answer























          • Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

            – user3720465
            2 days ago












          • This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

            – user3720465
            2 days ago











          • With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

            – user3720465
            2 days ago











          • The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

            – user3720465
            2 days ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          user3720465 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033653%2fc-sharp-what-is-best-practise-for-handling-data-errors-and-warnings-as-opposed-t%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Microsoft and SOLID are right.



          The correct way to go are Exceptions as per standard practices (and c#), independently of another considerations, like performance for instance.



          Generally speaking there are two different types of "Errors", technical, and business logic related.



          Failing to Connect to a DB, receiving a 500 from a REST Service, etc... are technical, and as they could be transient you can try to recover from this situation, sometimes without success, what finally causes the Business Orchestration/Process failure.



          Business Logic errors, like 'Customer already exists', 'Bank details invalid','Input data is not in the valid format' are non-transient, and determined solely by Business Rules (some implicit, other explicit) and will stop stop your process as well without possibility to recover, simply because something is not in the proper/expected state.



          There is a reason we use Exceptions (as technical artifacts) and is to handle these hard-stops 'properly'.



          Every time you throw an Exception the application traverse back the stack up to the first available Exception Handler able to handle such Exception, returning the control to you and to a known location where something will happen (telemetry, rethrow, show a dialog to the user...)



          Any mechanism trying to substitute this propagation (Error) must rely, for instance, on hijacking the return value of the methods to provide back a status, or forcibly include an out parameter to all your methods signatures, which will have awful collateral effects in your implementation.



          Yes, sometimes your current design look 'too flat' that you are tempted to hijack the return value here and there, creating a highly coupled component, but you never can tell how the system complexity will grow, meaning that at some point you will extend your system with additional layers, and most likely the 'substituting mechanism' approach will not fit , and you are forced to support them, the regular way and the imaginative one.



          So, trying to implement a custom solution will create a tightly-coupled technical requirement that must be supported all across the board, what in architecture terms is simply 'not good' (not a good practice)



          IF any Service you are consuming is not able to produce a meaningful 'error' information, well structured, then, the Service is not well designed, and the problem flips to the Client side (Talking in SOA terms).



          The only 'most correct' solution left to not introduce chaos in your Client is by creating a Proxy to the Service RESPECTING the rules required by your implementation approach.



          My recommendation about Error Handling is very simple, stick to the rules that are well know and have been in place for decades and do not try workaround this by yourself, or you are going to face too many issues, create a Proxy for each service and integrate them properly in your code base (unit testing and such)



          In regards to warnings, there is no recommendation from anybody to handle this by using Exceptions, those 'warnings' in your question is a normal output when interacting to the Service/a logical state supported by the Business Logic, thus, the place to handle this state is in the Data Contract coming back from the Service, again, if the Service is so horribly designed that is replying you with just a text string containing the word 'warning', and you are forced to parse this string to notice the situation, then your Proxy to the Service should check for it and provide a meaningful and well structured output to the Client.






          share|improve this answer























          • Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

            – user3720465
            2 days ago












          • This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

            – user3720465
            2 days ago











          • With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

            – user3720465
            2 days ago











          • The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

            – user3720465
            2 days ago















          0














          Microsoft and SOLID are right.



          The correct way to go are Exceptions as per standard practices (and c#), independently of another considerations, like performance for instance.



          Generally speaking there are two different types of "Errors", technical, and business logic related.



          Failing to Connect to a DB, receiving a 500 from a REST Service, etc... are technical, and as they could be transient you can try to recover from this situation, sometimes without success, what finally causes the Business Orchestration/Process failure.



          Business Logic errors, like 'Customer already exists', 'Bank details invalid','Input data is not in the valid format' are non-transient, and determined solely by Business Rules (some implicit, other explicit) and will stop stop your process as well without possibility to recover, simply because something is not in the proper/expected state.



          There is a reason we use Exceptions (as technical artifacts) and is to handle these hard-stops 'properly'.



          Every time you throw an Exception the application traverse back the stack up to the first available Exception Handler able to handle such Exception, returning the control to you and to a known location where something will happen (telemetry, rethrow, show a dialog to the user...)



          Any mechanism trying to substitute this propagation (Error) must rely, for instance, on hijacking the return value of the methods to provide back a status, or forcibly include an out parameter to all your methods signatures, which will have awful collateral effects in your implementation.



          Yes, sometimes your current design look 'too flat' that you are tempted to hijack the return value here and there, creating a highly coupled component, but you never can tell how the system complexity will grow, meaning that at some point you will extend your system with additional layers, and most likely the 'substituting mechanism' approach will not fit , and you are forced to support them, the regular way and the imaginative one.



          So, trying to implement a custom solution will create a tightly-coupled technical requirement that must be supported all across the board, what in architecture terms is simply 'not good' (not a good practice)



          IF any Service you are consuming is not able to produce a meaningful 'error' information, well structured, then, the Service is not well designed, and the problem flips to the Client side (Talking in SOA terms).



          The only 'most correct' solution left to not introduce chaos in your Client is by creating a Proxy to the Service RESPECTING the rules required by your implementation approach.



          My recommendation about Error Handling is very simple, stick to the rules that are well know and have been in place for decades and do not try workaround this by yourself, or you are going to face too many issues, create a Proxy for each service and integrate them properly in your code base (unit testing and such)



          In regards to warnings, there is no recommendation from anybody to handle this by using Exceptions, those 'warnings' in your question is a normal output when interacting to the Service/a logical state supported by the Business Logic, thus, the place to handle this state is in the Data Contract coming back from the Service, again, if the Service is so horribly designed that is replying you with just a text string containing the word 'warning', and you are forced to parse this string to notice the situation, then your Proxy to the Service should check for it and provide a meaningful and well structured output to the Client.






          share|improve this answer























          • Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

            – user3720465
            2 days ago












          • This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

            – user3720465
            2 days ago











          • With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

            – user3720465
            2 days ago











          • The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

            – user3720465
            2 days ago













          0












          0








          0







          Microsoft and SOLID are right.



          The correct way to go are Exceptions as per standard practices (and c#), independently of another considerations, like performance for instance.



          Generally speaking there are two different types of "Errors", technical, and business logic related.



          Failing to Connect to a DB, receiving a 500 from a REST Service, etc... are technical, and as they could be transient you can try to recover from this situation, sometimes without success, what finally causes the Business Orchestration/Process failure.



          Business Logic errors, like 'Customer already exists', 'Bank details invalid','Input data is not in the valid format' are non-transient, and determined solely by Business Rules (some implicit, other explicit) and will stop stop your process as well without possibility to recover, simply because something is not in the proper/expected state.



          There is a reason we use Exceptions (as technical artifacts) and is to handle these hard-stops 'properly'.



          Every time you throw an Exception the application traverse back the stack up to the first available Exception Handler able to handle such Exception, returning the control to you and to a known location where something will happen (telemetry, rethrow, show a dialog to the user...)



          Any mechanism trying to substitute this propagation (Error) must rely, for instance, on hijacking the return value of the methods to provide back a status, or forcibly include an out parameter to all your methods signatures, which will have awful collateral effects in your implementation.



          Yes, sometimes your current design look 'too flat' that you are tempted to hijack the return value here and there, creating a highly coupled component, but you never can tell how the system complexity will grow, meaning that at some point you will extend your system with additional layers, and most likely the 'substituting mechanism' approach will not fit , and you are forced to support them, the regular way and the imaginative one.



          So, trying to implement a custom solution will create a tightly-coupled technical requirement that must be supported all across the board, what in architecture terms is simply 'not good' (not a good practice)



          IF any Service you are consuming is not able to produce a meaningful 'error' information, well structured, then, the Service is not well designed, and the problem flips to the Client side (Talking in SOA terms).



          The only 'most correct' solution left to not introduce chaos in your Client is by creating a Proxy to the Service RESPECTING the rules required by your implementation approach.



          My recommendation about Error Handling is very simple, stick to the rules that are well know and have been in place for decades and do not try workaround this by yourself, or you are going to face too many issues, create a Proxy for each service and integrate them properly in your code base (unit testing and such)



          In regards to warnings, there is no recommendation from anybody to handle this by using Exceptions, those 'warnings' in your question is a normal output when interacting to the Service/a logical state supported by the Business Logic, thus, the place to handle this state is in the Data Contract coming back from the Service, again, if the Service is so horribly designed that is replying you with just a text string containing the word 'warning', and you are forced to parse this string to notice the situation, then your Proxy to the Service should check for it and provide a meaningful and well structured output to the Client.






          share|improve this answer













          Microsoft and SOLID are right.



          The correct way to go are Exceptions as per standard practices (and c#), independently of another considerations, like performance for instance.



          Generally speaking there are two different types of "Errors", technical, and business logic related.



          Failing to Connect to a DB, receiving a 500 from a REST Service, etc... are technical, and as they could be transient you can try to recover from this situation, sometimes without success, what finally causes the Business Orchestration/Process failure.



          Business Logic errors, like 'Customer already exists', 'Bank details invalid','Input data is not in the valid format' are non-transient, and determined solely by Business Rules (some implicit, other explicit) and will stop stop your process as well without possibility to recover, simply because something is not in the proper/expected state.



          There is a reason we use Exceptions (as technical artifacts) and is to handle these hard-stops 'properly'.



          Every time you throw an Exception the application traverse back the stack up to the first available Exception Handler able to handle such Exception, returning the control to you and to a known location where something will happen (telemetry, rethrow, show a dialog to the user...)



          Any mechanism trying to substitute this propagation (Error) must rely, for instance, on hijacking the return value of the methods to provide back a status, or forcibly include an out parameter to all your methods signatures, which will have awful collateral effects in your implementation.



          Yes, sometimes your current design look 'too flat' that you are tempted to hijack the return value here and there, creating a highly coupled component, but you never can tell how the system complexity will grow, meaning that at some point you will extend your system with additional layers, and most likely the 'substituting mechanism' approach will not fit , and you are forced to support them, the regular way and the imaginative one.



          So, trying to implement a custom solution will create a tightly-coupled technical requirement that must be supported all across the board, what in architecture terms is simply 'not good' (not a good practice)



          IF any Service you are consuming is not able to produce a meaningful 'error' information, well structured, then, the Service is not well designed, and the problem flips to the Client side (Talking in SOA terms).



          The only 'most correct' solution left to not introduce chaos in your Client is by creating a Proxy to the Service RESPECTING the rules required by your implementation approach.



          My recommendation about Error Handling is very simple, stick to the rules that are well know and have been in place for decades and do not try workaround this by yourself, or you are going to face too many issues, create a Proxy for each service and integrate them properly in your code base (unit testing and such)



          In regards to warnings, there is no recommendation from anybody to handle this by using Exceptions, those 'warnings' in your question is a normal output when interacting to the Service/a logical state supported by the Business Logic, thus, the place to handle this state is in the Data Contract coming back from the Service, again, if the Service is so horribly designed that is replying you with just a text string containing the word 'warning', and you are forced to parse this string to notice the situation, then your Proxy to the Service should check for it and provide a meaningful and well structured output to the Client.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 1:22









          Jesus SalasJesus Salas

          38819




          38819












          • Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

            – user3720465
            2 days ago












          • This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

            – user3720465
            2 days ago











          • With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

            – user3720465
            2 days ago











          • The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

            – user3720465
            2 days ago

















          • Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

            – user3720465
            2 days ago












          • This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

            – user3720465
            2 days ago











          • With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

            – user3720465
            2 days ago











          • The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

            – user3720465
            2 days ago
















          Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

          – user3720465
          2 days ago






          Many thanks ... the advice is much appreciated This is actually a re-write of an existing system, so we have Proxy server in place for the testing. It sounds like it is the approach to warning messages and ensuring the design is correct, which stil leaves us in a hole. A number of the 3rd party systems provide a simple binary responses to completion, but we have a growing number of scenarios (hence the re-write) with orders where response is not so clear cut as in the case of credit loan requests and conformation and dates from the supplier

          – user3720465
          2 days ago














          This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

          – user3720465
          2 days ago





          This can result in us entering a work flow with the 3rd party. The responses can be simple Yes or No, but most of the time now the decision to accept can be deferred.

          – user3720465
          2 days ago













          With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

          – user3720465
          2 days ago





          With any responses from a 3rd party the Application Service processes work flow tasks. The return data from the 3rd party along with the message plays a vital role in determining what happens with workflow tasks and what status to place the customers order in after such a benign request as Create Customer or Create Order..

          – user3720465
          2 days ago













          The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

          – user3720465
          2 days ago





          The hole being we need the the data and message being returned, the only thing I can conclude is that this has to serialised by the the Repository whether in the form of a work flow tasks or order status , therefore in regards warnings this should not be considered as exception rather forms part of the entity being returned by the ReastAPi Service.

          – user3720465
          2 days ago












          user3720465 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          user3720465 is a new contributor. Be nice, and check out our Code of Conduct.












          user3720465 is a new contributor. Be nice, and check out our Code of Conduct.











          user3720465 is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033653%2fc-sharp-what-is-best-practise-for-handling-data-errors-and-warnings-as-opposed-t%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme