Home > Error Code > C# Error Codes Vs Exceptions

C# Error Codes Vs Exceptions


Frank 11:45 AM on 14 Sep 2006 I arrived at your page by Googling: "C++" exceptions return status method comparison Unfortunately, your site picked up that fact and highlighted in different Jason Kozak 2:37 PM on 15 Nov 2003 I'm not sure why people keep bringing up performance hits with regards to exceptions. I can't belive that this is even open for discussion anymore. And then the code to clean up, or handle the "exceptional" circumstances when something bad happens that prevents the method from completing successfully can be siloed away from the normal code. Source

It's really a compromise, error codes are for when you either need absolute best performance, or you need to deal with the error code locally, exceptions are much better when you Is there a command for running a script according to its shebang line? Two tails in a row - what's the probability that the game started with a head? I've seen many times that exceptions are thrown an caught 20 steps down the call stack and of course that leads to almost unpredictable software. #35 Stefan on 09.26.12 at 3:40

Error Code Vs Exception

And if measurementOnePlusTwo is required within some method then that must stop processing as well. share|improve this answer answered Oct 31 '08 at 12:39 Maxam 3,23721625 add a comment| up vote 11 down vote Exceptions over error codes, no doubt about it. You might as well return an enum instead, its a lot faster and significantly easier to read error return code than litter everything with 7 lines of code instead of 1. To avoid this situation, you can deploy the assembly that contains the exception information in two ways: Put the assembly into a common application base shared by both app domains. -

  1. With well written exception based code, unexpected failures eventually cause an unhandled exception handler to be called.
  2. Ever.
  3. As far as hijacking the return value, I don't.

try { <...> for ( int i = 0 ; i < n ; i++ ) DebugLog("Trying myCall with i = " + i); myCall(); <...> } catch ( Exception exception For example, IMHO, a general file_open function should not throw an exception, if the file doesn't exist. I would prefer non-exception throwing functions for at least these two cases (open and parse). Which Type Of Testing Requires Stubs And Drivers Brit 7:43 PM on 24 Oct 2003 First of all, exceptions and status do not solve the same problem.

it uses exceptions because returning error codes would make the calling code dependent on the called method (object). Do you have any elegant solution ? Exceptions has a lot of information you might not need. Sure, we might dig into our current behavior and speed it up a little.

How does my caller translate that error into a user-understanble error message. C# Custom Exception C as an intermediate language Error codes vs exceptions: critical code vs typical code Aren't side effects fundamental in complexity analysis? It appears that the GCC flags I used generated unusually slow exceptions compared to the other compilers. share|improve this answer answered Aug 2 '12 at 1:53 Scott Whitlock 19.2k34177 2 Personally, I often use a result container like your IMyResult cause it is possible to communicate a

Exception Error Code Java

Without a way to express the failure, your system will only grow more error-prone and mysterious. So you've traded implicit complexity for explicit complexity, which may not be a good trade. Error Code Vs Exception There typically are 10 kinds of people, those who think in binary and those who don't... The Exception That Grounded An Airline the sample should be more like: STATUS DoSomething(int a, int b) { STATUS retVal = DoThing1(a); if (retVal == SGOOD) retVal = DoThing2(b); return retVal; } This is absolutely fine, especially

I don't think Joel's second argument is even valid. http://patricktalkstech.com/error-code/cch-error-codes.html The API developer can customize the exception subclass as much as necessary to transmit all of the details of the error to the caller. size=2>Exceptions Promote Instrumentation In fact one disadvantage of C++ exceptions is that they unwind the call stack - I'd much prefer an uncaught C++ exception to dump core without unwinding the call stack. (It's See ASP.NET Ajax CDN Terms of Use – http://www.asp.net/ajaxlibrary/CDN.ashx. ]]> | Search MSDN Search all blogs Search this blog Exceptions Vs Return Codes C++

status returns There are some good links in those that can give you further reading. You're getting some anyway, but many of them will not apply. –Darron Jan 14 '09 at 21:25 It was in C# - thanks for your hint. –SRO Jan 14 But is it really hard to read and write "if (response.Status == Statuses.Success) { var value = response.Value; }" instead of try-catch? have a peek here Do I need to call another function to get the error code?

Throw exception when the semantics of the function is that the caller is sure that it will work. Test Cases Can Be Designed In The Exploratory Testing share|improve this answer answered Jan 14 '09 at 21:07 Konrad Rudolph 323k76660911 add a comment| up vote 2 down vote First things, first. This is the problem, so focus on it.

Thus, I have to know or guess about errors on both ways to handle errors, not only on exceptions.

string circuitCommand = "GSV,01," + sensorNumber.ToString(); // Get measurement command for specified sensor. If you find that while using exceptions your code gets run down with them and bloated by exception based classes you, once again, don't fully understand exceptions and how to use So I think it makes sense for Go - a language for writing critical production code - to shun exceptions. C# Exception Error Code When you catch the object, tell it to display its context information to the log file, and/or the screen and/or whereever you want it to.

By employing exceptions, you are forcing something like a 100 times slow down on callers who will see the exception on half of their (many) calls, if the body of the Is it a stochastic matrix? I don't want to define a magic number if I'm returning a double, and I don't want to throw an exception. Check This Out Error codes are far safer for well-reviewed, critical code. (As you can see from 2 and 3, I believe that most code is not critical and/or poorly reviewed; I think most

Word to describe object that can be physically passed through Head, Shoulders, Knees and Toes, Knees and Toes A 17th century colloquial term for children, in the way we use 'kids' asked 3 years ago viewed 4841 times active 2 years ago Related 11Exceptions or Error codes60Return magic value, throw exception or return false on failure?6Exception Handling Frequency/Log Detail4When is it worthwhile Read that again, its important. Create an enum and throw this enum, catch and do a switch( my_error_enum ), which by nature cascades through (unless on break), and cleanup in reverse order of the function calls.

I don't get why people add this crap feature to their blogs. Can the device resume normal operation? Unhandled exceptions stop program execution.An exception jumps to the point in the call stack that can handle the error. But as a general rule, I'd say: stick to Exceptions, it's simple, informative, debuggable and easy to handle even though it might come at a slight performance cost share|improve this answer

For a more details, see Design Guidelines for Exceptions.Design classes so that an exception is never thrown in normal use. Multiple exit points are just a prevalent in non-exceptional :) code as it is with exceptional code. E.g.