Why bother with any other exception data? The message should suffice.
-
try
{
//do stuff that may fail
}
catch (Exception e)
{
throw new Exception(e.Message);
}This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
-
try
{
//do stuff that may fail
}
catch (Exception e)
{
throw new Exception(e.Message);
}This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
"An error has occurred, see the inner exception for details."
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
try
{
//do stuff that may fail
}
catch (Exception e)
{
throw new Exception(e.Message);
}This is from an online tutorial I recently came across (thankfully not in CP). Apparently if something goes wrong, one can get ALL the information one needs from the exception message. Why bother with stacktrace etc... ... or that's what the author thought, anyway.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
-
Quote:
//do stuff that may fail
Well there's the real problem. Why would you purposely write code that may fail. Write it to not fail. Duh!
There are only 10 types of people in the world, those who understand binary and those who don't.
-
I agree -- and not as a joke. In general code should not fail*. * -- in case you see my code fail: it was by design.
Greetings - Jacek
Continuing on your serious note: the code per se, should not fail, I agree. But the final program may fail at times. Say you have a web request in there, and any of the following occurs: (a) the remote server times out (e.g. the server is offline) (b) the remote server has a bug, returning a 500 error (c) the remote server cannot find the requested resource, returning a 404 error (d) the remote server forbids access to the requested resource, returning a 403 error Any of the above results in the web request throwing an exception in YOUR application, but your code is not to blame. So there is a chance that a bug-free program CAN fail. That's why you should have error handling and meaningful error reporting.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
-
"An error has occurred, see the inner exception for details."
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
Yeah my point exactly. I'd done that same mistake myself, and thankfully it never got past the testing phase: I got that exact error message, and there was no inner exception to see :), so after a bit of digging, I simply changed my
throw new Exception(ex.Message);
to
throw;
(Of course, I had an error logging call just before that, otherwise the entire catch block wouldn't make much sense...) I was just very (unpleasantly) surprised to come across such a basic coding mistake in an online tutorial.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων! (Alas! We're devoured by lamb-guised wolves!)
-
Quote:
//do stuff that may fail
Well there's the real problem. Why would you purposely write code that may fail. Write it to not fail. Duh!
There are only 10 types of people in the world, those who understand binary and those who don't.
Bugs happen.