Error handling in Bash

Use a trap! …then, whenever you create a temporary file: and $temp_foo will be deleted on exit, and the current line number will be printed. (set -e will likewise give you exit-on-error behavior, though it comes with serious caveats and weakens code’s predictability and portability). You can either let the trap call error for you (in which case it uses the default … Read more

Handling a timeout error in python sockets

adds all the names without leading underscores (or only the names defined in the modules __all__ attribute) in foo into your current module. In the above code with from socket import * you just want to catch timeout as you’ve pulled timeout into your current namespace. from socket import * pulls in the definitions of everything inside of socket but doesn’t add socket itself. Many people consider import * problematic and try … Read more

try catch ArrayIndexOutOfBoundsException?

I don’t see an array anywhere in your code, so that’s maybe why the try block isn’t catching anything (I assume there is an array in one of the called methods?). Also, you really, really shouldn’t allow your program to read outside the bounds of an array. That’s just bad design. That being said, here … Read more