Proper Exception Handling: Try-Catch Blocks with Loops in Cryptographic Hash Collision Program
Hello everyone!
I'm working on a cryptographic hashing project where I need to find hash collisions for multiple messages. I'm a bit confused about the proper way to structure my try-catch blocks with loops.
Here's my situation: I have an array of messages that I need to process:
I need to hash each message and find collisions, but I'm not sure about the correct way to handle exceptions. Should I:
1. Put the try-catch block inside the for loop:
2. Or wrap the entire loop in a try-catch:
Which approach is better for this kind of cryptographic processing? I want to make sure I'm handling exceptions properly while finding hash collisions. Thanks in advance for any help! 🙏
4 Replies
⌛
This post has been reserved for your question.
Hey @dghf! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
depends on what you want to be processed when a failure occurs
if you want to stop processing all messages, then it makes sense to keep the loop in the
try
, so it stops running if an exception is thrown
if you want to trigger an error per message, but keep the loop running if an exception occurs, put the try/catch
inside the loopInstead of creating a new
MessageDigest
in each iteration, you could also create it once outside of the loop and then call reset()
after each iteration💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.