Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 22:01:34 +0000



Why Software Code Exceptions are Wrong

View Count: 1089

[2017-06-02 16:03:29]
Sierra Chart Engineering - Posts: 104368
This is the beginning of a public article on why programming exceptions are wrong and should never be used. Even at the hardware level, the way that exceptions are being managed and used, is also wrong.

One problem with the exceptions is they are used in cases where there is not an exceptional condition such as an invalid parameter or data which cannot be parsed. None of these are exceptional conditions despite if some idiot programmer thinks they are.

In general exceptions are wrong because they cause a wild jump of execution to another point in the code unless they are handled, there is complexity in code to handle the exceptions, and if they are frequently used, this massively complicates code and takes a lot more time and makes the code very disorganized. Also the logical flow of execution is disrupted. Also when an exception occurs, if it is not handled, a program halts even over something trivial such as unable to open a file or integer division by zero.

You might think aan integer division by zero is an exceptional condition. It is completely and totally ludicrous to terminate an entire process over a division by zero. Instead the exception should be logged so the programmer knows and continue execution. It would be best to simply set the variable that will receive the result to the maximum value of the integer type.

One reason Sierra Chart is so stable is because nowhere in the Sierra Chart code base, are exceptions used.

There are exceptions which can be thrown by some Microsoft MFC functions, and also by the XML and JSON parser and also Google protocol buffers. We disagree with all of these. But we catch them as best as we can.

The Microsoft Windows SDK does not use exceptions.

CPUs do use exceptions but we disagree in the way that they are managed by the operating system.

These views are also shared here:
https://stackoverflow.com/questions/1736146/why-is-exception-handling-bad

One reason exceptions are wrong is that you cannot know definitively what type of an exception is going to be thrown by a function. It is necessary to add a catch block for every type of an exception which could be thrown which could be numerous ones. This kind of programming requirement is totally and completely absurd. It is also necessary to catch an exception using ... which is typically what we do when we need to due to exceptions thrown by external libraries because we cannot know the type of exception. But this also limits the gathering information about the exception.


We maintain the position that the concept of an exception is wrong and illogical. They only have a place at the CPU instruction code level and even then, halting a program on an exception is simply wrong. It should be up to the programmer to make that decision and the operating system should simply log the exception for the application and have a method limit logging when there is an excessive number of exceptions over a short period of time.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-06-02 16:15:45
[2017-06-02 16:18:44]
Sierra Chart Engineering - Posts: 104368
There may be the argument, that terminating a program on an exception like a division by zero or access violation makes sense because the program is doing something wrong and it should be halted rather than leaving it in a state where it is doing something potentially seriously wrong. There is no way this can be concluded definitively. These kinds of exceptions do not necessarily indicate that.

This argument is not valid because a program can do all kinds of seriously wrong things like using 100 percent of the CPU time of a core on a high priority thread, having a serious memory leak which uses a large amount of system memory and possibly bringing the system to a crawl, or writing to a file endlessly causing a huge amount of disk space to be used and consuming all of the available space. These are very detrimental things a program could do all without triggering an exception.

there needs to be a method by which a division by zero or an access violation is signaled and handled, but an abrupt termination is not the proper solution in all cases.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-06-03 01:42:33
[2017-06-03 01:42:59]
Sierra Chart Engineering - Posts: 104368
More information on the subject:
http://www.lighterra.com/papers/exceptionsharmful/
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2017-06-03 03:51:39

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account