Click here to Skip to main content
15,881,588 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exceptions Pin
Simon_Whale17-Jan-22 3:53
Simon_Whale17-Jan-22 3:53 
AnswerRe: Exceptions Pin
OriginalGriff17-Jan-22 3:41
mveOriginalGriff17-Jan-22 3:41 
GeneralRe: Exceptions Pin
Simon_Whale17-Jan-22 3:53
Simon_Whale17-Jan-22 3:53 
AnswerRe: Exceptions Pin
Luc Pattyn17-Jan-22 3:59
sitebuilderLuc Pattyn17-Jan-22 3:59 
QuestionRe: Exceptions Pin
Simon_Whale18-Jan-22 5:05
Simon_Whale18-Jan-22 5:05 
AnswerRe: Exceptions Pin
Gerry Schmitz17-Jan-22 6:07
mveGerry Schmitz17-Jan-22 6:07 
GeneralRe: Exceptions Pin
Simon_Whale18-Jan-22 5:06
Simon_Whale18-Jan-22 5:06 
AnswerRe: Exceptions Pin
lmoelleb18-Jan-22 4:55
lmoelleb18-Jan-22 4:55 
Look at the points where you expose data from the backend (typically a REST service or similar). If an exception is raised, you generally speaking just return "500 Internal Server error" without any further details - and (very important) log those details on the server.

In case you use exception to trigger responses like like "404 NOT FOUND" you need to make sure they do not show stack traces or internal details as well.

This is typically done in a central place in the response handler of the API so it will automatically kick in for any exception raised - you need to write this code and test it so you trust it no matter which exception is raised from the lower levels of the code. Then you do not need to hunt your entire code base for possible exceptions - which is an impossible task anyway as some system exceptions can be raised from anywhere.

Java tried to get the code to declare all exceptions so you could track it down (checked exceptions) but it was not a great success.

UPDATE: And make sure you only catch exceptions in 2 cases:
1) When you can FIX the issue - i.e. no error will be returned to the client, and hence no information will be leaked. Example: You want to read some data from a disk cache. If the read throws an exception catch it and recalculate the data.
2) When you can throw an exception with more details. Example: You try to read the data but the exception just says "Access denied". You know what you where trying to read and which user you where running as, so catch it and throw a new exception adding these datails - keeping the original exception as inner exception.
QuestionRe: Exceptions Pin
Eddy Vluggen18-Jan-22 19:32
professionalEddy Vluggen18-Jan-22 19:32 
AnswerRe: Exceptions Pin
lmoelleb18-Jan-22 20:40
lmoelleb18-Jan-22 20:40 
GeneralRe: Exceptions Pin
Eddy Vluggen19-Jan-22 0:40
professionalEddy Vluggen19-Jan-22 0:40 
GeneralRe: Exceptions Pin
lmoelleb19-Jan-22 0:48
lmoelleb19-Jan-22 0:48 
GeneralRe: Exceptions Pin
Eddy Vluggen19-Jan-22 1:12
professionalEddy Vluggen19-Jan-22 1:12 
AnswerRe: Exceptions Pin
Eddy Vluggen18-Jan-22 18:02
professionalEddy Vluggen18-Jan-22 18:02 
AnswerRe: Exceptions Pin
jschell23-Jan-22 7:32
jschell23-Jan-22 7:32 
Questionnecessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 2:39
professionalBillWoodruff16-Jan-22 2:39 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
harold aptroot16-Jan-22 3:21
harold aptroot16-Jan-22 3:21 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 5:14
professionalBillWoodruff16-Jan-22 5:14 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
harold aptroot16-Jan-22 6:56
harold aptroot16-Jan-22 6:56 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 18:22
professionalBillWoodruff16-Jan-22 18:22 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming16-Jan-22 22:45
mveRichard Deeming16-Jan-22 22:45 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff18-Jan-22 1:19
professionalBillWoodruff18-Jan-22 1:19 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming18-Jan-22 1:41
mveRichard Deeming18-Jan-22 1:41 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff18-Jan-22 3:08
professionalBillWoodruff18-Jan-22 3:08 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming18-Jan-22 6:17
mveRichard Deeming18-Jan-22 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.