Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to throw a general exception like "WebException" whenever i receive a code : 500 internal server error from a HTTP Response in C#. Can you please suggest me which exception to throw?

What I have tried:

I have written a Internal Server Exception Class but the requirement is to throw some general exception.
Posted
Updated 9-Jun-17 19:49pm

Personally, I'm all in favor of building a specific exception class for an internal server error, especially if this code is going to hang around for a while, but if this is just an exercise, or it's a throw-away one off, then a generic "throw new Exception(<messagehere>);" works just fine and fulfills the requirement
 
Share this answer
 
Comments
Member 13241216 5-Jun-17 9:47am    
I just want to know , if there is any predefined exception for Code 500
Well, HTTP status codes (including 500) are supposed to be sent across the wire from server to the client as part of a response, no matter which platform the client is built from. Whereas, the exceptions are specific to the run-time environment, using which the server code is built. Further, the exceptions are not propagated till the client, but rather logged and in severe condition, notified to the system administrator. Hence, to my opinion, there should be specific exception classes instead of one general exception class. Further, these exception classes should represent in which application layer (e.g. DA layer, business service, Database) the exception is raised. This will help identify and troubleshoot the issues quickly behind the scene.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900