|
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
I just stuck this in a small data import utility that I don't particularly care about:
catch ( System.Data.DataException err )
{
if ( !err.ToString().Contains ( "Cannot insert duplicate key" ) )
{
throw ;
}
}
If they don't care enough to send me clean data, why should I spend a Friday afternoon writing good code?
modified 7-Aug-15 16:45pm.
|
|
|
|
|
that's the way to do it... why should always we developers have the pressure of being exact and clean
would've done it too this way... if it was friday afternoon in the mid of summer
|
|
|
|
|
PIEBALDconsult wrote: err.ToString()
Whatever happened to err.Message ?
Marc
|
|
|
|
|
Nah, I tried that first, but the text is in an InnerException.
I have code that spelunks the Exceptions looking for the actual Error code from SQL Server, but I didn't have it handy.
|
|
|
|
|
If it's in the innermost exception:
catch ( System.Data.DataException err )
{
if ( !err.GetBaseException().Message.Contains ( "Cannot insert duplicate key" ) )
{
throw;
}
}
Exception.GetBaseException Method | MSDN[^]
If it can be anywhere in the chain:
catch ( System.Data.DataException err )
{
bool isDuplicateKey = false;
Exception currentErr = err;
while (currentErr != null && !isDuplicateKey)
{
isDuplicateKey = currentErr.Message.Contains ( "Cannot insert duplicate key" );
currentErr = currentErr.InnerException;
}
if ( !isDuplicateKey )
{
throw;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Though I can see the improvement; wouldn't the weak spot here being the check for a localized message? IIRC, then different (localized) versions of .NET will give different results.
"Kan geen rij met dubbele sleutel invoegen in object 'dbo.aa673 met unieke index 'IX_673'."
Next you'll hear "It worked on Win7, and then I opened it on another machine and it crashed. We didn't change anything and it should still be working. Why does Windows do that?"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Indeed. Checking the SQL error codes would be a more robust approach.
However, it sounds like this is a program that's only ever run on one computer, so it's unlikely to suddenly start throwing errors in Dutch.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: However, it sounds like this is a program that's only ever run on one computer I wish I had gotten a penny everytime that assumption fell apart
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
When I do it right, I walk the InnerExceptions to find the first System.Data.SqlClient.SqlException with one of the following error codes:
errorcodes = new System.Collections.Generic.Dictionary<int,PIEBALD.Data.ErrorCode>() ;
errorcodes [ 1205 ] = PIEBALD.Data.ErrorCode.Deadlock ;
errorcodes [ 2601 ] = PIEBALD.Data.ErrorCode.Duplicate ;
errorcodes [ 2627 ] = PIEBALD.Data.ErrorCode.Duplicate ;
errorcodes [ 547 ] = PIEBALD.Data.ErrorCode.ReferentialIntegrity ;
errorcodes [ -2 ] = PIEBALD.Data.ErrorCode.Timeout ;
Then wrap it in a custom Exception:
public partial class DuplicateException : PIEBALD.Data.OperationFailedException ...
public partial class ReferentialIntegrityException : PIEBALD.Data.OperationFailedException ...
public partial class TimeoutException : PIEBALD.Data.OperationFailedException ...
Then my code can catch and act on specific error codes.
|
|
|
|
|
What if locale is not english
TVMU^P[[IGIOQHG^JSH A#@ RFJ\c^JPL>;"[, /|+&WLEZGc
AFXc!L<br />
%^]*IRXD#@GKCQ R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_ADEPABIKRDFVS)EVLQK)JKQUFK[M UKs$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
ALTER TABLE [tablename] ADD DEFAULT (NULL) FOR [fieldname]
Well yes - that should make a huge difference....
|
|
|
|
|
Duncan Edwards Jones wrote: that should make a huge difference You can never be too clear.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Then why is there no comment explaining the default?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Then why is there no comment explaining the default? Reminds me of some code I inherited.
DataManager dm = new DataManager();
dm.Open();
Ya, thanks for the helpful comment.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
That is rather helpful; it explains that the DataManager is merely a wrapper round a connection, and that it probably should be deleted from the project and simply replaced by an IDbConnection and a factory
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Working on Google sign in API for one of my project which need to load one j query file called
https://apis.google.com/js/client:plusone.js
i copy this link send it to my co-worker by Skype, he copied and apply that code. Boom, g-sign in button do not click. the same code working fine on the test project that we have created but not on our main project.
Reason,
Skype see "client:plusone.js" and convert :P to and when same code goes to vs it leaves a blank space and copied like "client lusone.js". after spending some half an hour we finally got a working example of Google sign in.
Ravi Khoda
|
|
|
|
|
Thank God the code didn't use mooning
|
|
|
|
|
Words just fail me...
Help wiht a code[^]
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
|
It has been removed. What did it say?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Have not seen it either, but from the tip of my tongue Id' guess it was similar to what my link below Shows off...
|
|
|
|
|
Thanks Marco, that's the one.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
It was someone trying to compile poorly formatted XML as C++
I don't know why.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|