Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
GeneralRe: Exception Handling / Response Question Pin
PIEBALDconsult20-Jun-14 7:37
mvePIEBALDconsult20-Jun-14 7:37 
GeneralRe: Exception Handling / Response Question Pin
Kevin Marois20-Jun-14 7:39
professionalKevin Marois20-Jun-14 7:39 
GeneralRe: Exception Handling / Response Question Pin
PIEBALDconsult20-Jun-14 7:44
mvePIEBALDconsult20-Jun-14 7:44 
GeneralRe: Exception Handling / Response Question Pin
Kevin Marois20-Jun-14 7:52
professionalKevin Marois20-Jun-14 7:52 
GeneralRe: Exception Handling / Response Question Pin
PIEBALDconsult20-Jun-14 8:05
mvePIEBALDconsult20-Jun-14 8:05 
AnswerRe: Exception Handling / Response Question Pin
Eddy Vluggen20-Jun-14 8:05
professionalEddy Vluggen20-Jun-14 8:05 
GeneralRe: Exception Handling / Response Question Pin
Kevin Marois20-Jun-14 8:18
professionalKevin Marois20-Jun-14 8:18 
GeneralRe: Exception Handling / Response Question Pin
Eddy Vluggen20-Jun-14 9:21
professionalEddy Vluggen20-Jun-14 9:21 
Kevin Marois wrote:
1) Try/Catch blocks All Over.
Yup, those are a problem. If you don't intend to do something with it (logging should be done at the least amount of levels required) then don't write a handler. Let it bubble up. Don't add yet another empty handler.

Kevin Marois wrote:
You always want try/catch's wrapping your DAL data methods
Even if it is a Win32Exception whose error-message I can get, it is usually something the end-user can handle, not I. The options are often "try again" or "fail".

But then again, I don't do generic exception handling in a DAL-layer. If there's a disk-full message, then it bubbles up, is displayed, and can only be dismissed. The action can be tried again (by the user) after that oc. If it cannot be retried automatically, then there's no local handler, and the threads' exception handler will take care of it. There's sldo no need to catch-and-rethrow some validation exception, that's the responsibility of the calling code.

Kevin Marois wrote:
I do not agree that a duplicate record is an exception. First, it really is an
issue of the business rules.
You do not have to; it's not the BR-rules that define how the data is saved most efficiently. There technically cannot be "duplicate" records in a relational database. If your BR require for "duplicates", I'll add an identity-field (an artificial key in normalization terms) to distinguish between both entities. The identity would be the PK, and there'd be a unique key on the things you use to distinguish between records to identify (and if need be, notify) of breach of such a BR-constraint.

Kevin Marois wrote:
Second, the user types in "Blah" and saves, and then "Blah" again and saves, and
the app should log & throw?? Really? The app should notify the user, but no
other action is necessary.
It depends on the case. If it is a unique constraint, and a new baby gets an existing social security number, then you might want to throw an exception stating merely "computer says no". I do not know al the reasons why there cannot exist two identities with the same unique identifying key; only the user knows - and sometimes the dev has to remind the user he/she doesn't know either.

C#
[Serializable]
public class ComputerSaysNoException : Exception
{
  public ComputerSaysNoException() { }
  public ComputerSaysNoException( string message ) : base( message ) { }
  public ComputerSaysNoException( string message, Exception inner ) : base( message, inner ) { }
  protected ComputerSaysNoException(
    System.Runtime.Serialization.SerializationInfo info,
    System.Runtime.Serialization.StreamingContext context ) : base( info, context ) { }
}

Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: Exception Handling / Response Question Pin
Kevin Marois20-Jun-14 10:22
professionalKevin Marois20-Jun-14 10:22 
GeneralRe: Exception Handling / Response Question Pin
Eddy Vluggen20-Jun-14 11:05
professionalEddy Vluggen20-Jun-14 11:05 
QuestionPass specific object to a method expecting ref object parameter? Pin
arnold_w20-Jun-14 3:24
arnold_w20-Jun-14 3:24 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
Richard Deeming20-Jun-14 3:58
mveRichard Deeming20-Jun-14 3:58 
GeneralRe: Pass specific object to a method expecting ref object parameter? Pin
OriginalGriff20-Jun-14 3:59
mveOriginalGriff20-Jun-14 3:59 
GeneralRe: Pass specific object to a method expecting ref object parameter? Pin
Richard Deeming20-Jun-14 4:01
mveRichard Deeming20-Jun-14 4:01 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
OriginalGriff20-Jun-14 3:59
mveOriginalGriff20-Jun-14 3:59 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
PIEBALDconsult20-Jun-14 7:41
mvePIEBALDconsult20-Jun-14 7:41 
AnswerRe: Pass specific object to a method expecting ref object parameter? Pin
Eddy Vluggen20-Jun-14 8:47
professionalEddy Vluggen20-Jun-14 8:47 
Questionwhen using Stored Procedure called from C# ? Pin
Member 245846719-Jun-14 21:46
Member 245846719-Jun-14 21:46 
AnswerRe: when using Stored Procedure called from C# ? Pin
OriginalGriff19-Jun-14 22:21
mveOriginalGriff19-Jun-14 22:21 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846720-Jun-14 22:58
Member 245846720-Jun-14 22:58 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff20-Jun-14 23:22
mveOriginalGriff20-Jun-14 23:22 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846720-Jun-14 23:41
Member 245846720-Jun-14 23:41 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff21-Jun-14 0:06
mveOriginalGriff21-Jun-14 0:06 
GeneralRe: when using Stored Procedure called from C# ? Pin
Member 245846721-Jun-14 13:49
Member 245846721-Jun-14 13:49 
GeneralRe: when using Stored Procedure called from C# ? Pin
OriginalGriff21-Jun-14 19:43
mveOriginalGriff21-Jun-14 19:43 

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.