Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5161

Troubleshooting • Re: How do I call a function if there is an error?

$
0
0
You break down your code into logical pieces (functions, classes, ec). Then you turn your long code into shorter code that uses those smaller bits.

We don't know what language you use for your program, so we can't help with suggestions on how to do it. If this is related to your other threads, then you should be using python, and python has this thing called exceptions, where you put code in try blocks and handle errors in the exceptions blocks.

You should still log the errors, because you want to know you have errors, but you can then handle them appropriately. Some you may want to ignore, some you may not. But you always go back to your log.

How do you know you have any errors? You look at the log. You can also write code to send you an email if there was an error, or even call you on the phone with "hey, there was an error, look a the logs for more details", but you will still need to monitor the logs.


EDIT:

I see you have a LOT of issues with all of this. I think you would really be better off doing a few tutorials and projects from a book. There are many good ones out there, but here's 2 free ones:

1. Basic python course, with important basic things, like breaking up your code into more manageable code to make it simpler https://automatetheboringstuff.com/
2. The very first chapter on this book is about error handling. Should help you out too, though I really think you should do the other one above frist. https://inventwithpython.com/beyond/

We've all been there.

Good luck.

Statistics: Posted by memjr — Tue Apr 02, 2024 8:41 pm



Viewing all articles
Browse latest Browse all 5161

Trending Articles