i have a very fast question. As a reminder / notice: i'm new to micro controllers / PICS / Electronics. i'm not to programming.
Let's say i write this piece of code:for (int isz=5; isz>=0; --isz) { int something = somethingElse / isz; }
At a point of this loop, a division by 0 will happened.
What would be the expected behavior of my Arduino in such case?
Is there a general "thing" that happens when any kind of error occurs?
3a) Are try {} catch () {} / throw statements a good idea / available on such memory limited platform?
3b) If 3) = no, why? If 3) = yes, is there any way to get the stack and register states at the time of a crash?
4a) How do you guys handle errors (By errors, i don't mean "expected" errors, but more like "bugs errors") in your programs?
Is there a universal way to do it which would be good to learn, and which would be similar to all PICS micro controllers architectures?
Sorry for the load of questions... i'm eager to understand now
Thanks!
Pierre.
The simple way to handle a divide-by-zero is not to allow it to happen.
This is a microcontroller - there is no exception mechanism for stuff like this.
AWOL:
The simple way to handle a divide-by-zero is not to allow it to happen.This is a microcontroller - there is no exception mechanism for stuff like this.
Ha that's what i thought Thanks.
AWOL:
PICS
Wash your mouth out!
Sorry. Not having english as my native language + being new to the whole micro controller thing makes me say stuff which probably are horrible. You said that because PIC is a family, i'm sorry i shall have used "micro controllers" instead. i stand corrected, and i'm going to correct my initial posting.
Anyways, what would happened in my Arduino in the case of a division by zero?
Yes terminate is a more appropriate word for what i had in mind.
No. You may get meaningless data fi you try to read something. Other than that it is harmless to leave it as it is. Far as I know.
Ok, thanks for the answers!
If you're really clever, you could probably get it to erase all the program memory, but physical damage? No.
Hm. Very interesting. i guess i don't have the necessary knowledge yet to do it by itself, but with 2 of them, i think it would resemble to something like that:
Two chips (A and B) linked to each other and acting as programmers to each other when required.
A sends command to B.
B receives the command, and erases A, then uploads some other code to A.
A boots, and executes the code sent by B. It erases B.
The only thing left on A and B would be the code required to erase B which would still be on A