Throwing exception
-
I was reviewing source code. I found this piece
try {
if(!$var) {
// just this line;
throw new Exception("Exception related message");
}
// some other code
} catch(Exception e) {
// no code for handling the exception
// do some other irrelevant task
}:wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf:
I do not fear of failure. I fear of giving up out of frustration.
-
I was reviewing source code. I found this piece
try {
if(!$var) {
// just this line;
throw new Exception("Exception related message");
}
// some other code
} catch(Exception e) {
// no code for handling the exception
// do some other irrelevant task
}:wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf:
I do not fear of failure. I fear of giving up out of frustration.
Hahahaha... And it's the first time you encounter such code hey? Welcome to the club! :laugh: It seems to me that most code written by junior has such silly "exception handling"...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Hahahaha... And it's the first time you encounter such code hey? Welcome to the club! :laugh: It seems to me that most code written by junior has such silly "exception handling"...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
i have dealt with many madness in engineering. But this ticked me off. I cordially asked the engineer to fix. But he does not see the issue. but One good thing is he agreed to change the way i think it is okay
I do not fear of failure. I fear of giving up out of frustration.
-
i have dealt with many madness in engineering. But this ticked me off. I cordially asked the engineer to fix. But he does not see the issue. but One good thing is he agreed to change the way i think it is okay
I do not fear of failure. I fear of giving up out of frustration.
maybe he doesn't know about "return" statement or "finally" clause?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I was reviewing source code. I found this piece
try {
if(!$var) {
// just this line;
throw new Exception("Exception related message");
}
// some other code
} catch(Exception e) {
// no code for handling the exception
// do some other irrelevant task
}:wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf:
I do not fear of failure. I fear of giving up out of frustration.
Well, at first it seems that a simple if statement would do… However, if the condition should not occurs, it might be easier to find the problem during debugging if the debugger stop on exception or write something to the output log. But let assume that
some other code
might also throw anException
and if that case, you want to execute the code incatch
clause too, then it might be acceptable after all if that code should not be executed if no exception are thrown. As shown in the above example, all code can be removed as nothing else is done. In real code, it would not be the case! And the **cleanest** code to write directly depends on what missing code do and ifsome other code
could throw or not.Philippe Mori
-
maybe he doesn't know about "return" statement or "finally" clause?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
But do you know about the "fault" clause? It's like "finally", but only executes when an Exception was thrown. It's basically like:
catch
{
// Do something.
throw;
}But faster since the Exception isn't actually caught and rethrown. I guess it would look like:
fault
{
// Do something.
}The compiled MSIL code supports it, C# does not (which doesn't mean you can't use it[^] :cool:) :D
Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
Well, at first it seems that a simple if statement would do… However, if the condition should not occurs, it might be easier to find the problem during debugging if the debugger stop on exception or write something to the output log. But let assume that
some other code
might also throw anException
and if that case, you want to execute the code incatch
clause too, then it might be acceptable after all if that code should not be executed if no exception are thrown. As shown in the above example, all code can be removed as nothing else is done. In real code, it would not be the case! And the **cleanest** code to write directly depends on what missing code do and ifsome other code
could throw or not.Philippe Mori
You have an excellent point. But this is not the case. I would have understand the point very much if there were other codes that might have thrown exception. There is none :) that's why the frustration.
I do not fear of failure. I fear of giving up out of frustration.
-
But do you know about the "fault" clause? It's like "finally", but only executes when an Exception was thrown. It's basically like:
catch
{
// Do something.
throw;
}But faster since the Exception isn't actually caught and rethrown. I guess it would look like:
fault
{
// Do something.
}The compiled MSIL code supports it, C# does not (which doesn't mean you can't use it[^] :cool:) :D
Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
wow, you got me there pal! :omg:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
I was reviewing source code. I found this piece
try {
if(!$var) {
// just this line;
throw new Exception("Exception related message");
}
// some other code
} catch(Exception e) {
// no code for handling the exception
// do some other irrelevant task
}:wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf: :wtf:
I do not fear of failure. I fear of giving up out of frustration.
I wish this were weird, but one of the OOAD commandments I was taught was: "Thou shalt not use exceptions for flow control." Clearly all too common.
"Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor
-
I wish this were weird, but one of the OOAD commandments I was taught was: "Thou shalt not use exceptions for flow control." Clearly all too common.
"Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor