transaction not running if previous transactions fail

I have ultiple transaction in my code, inside a single try/catch. If a transaction fails, any transactions after it are never executed, despite them not being nested/connected in anyway.
4 Replies
NinjaBunny
NinjaBunny17mo ago
I’m pretty sure it’s because if the transaction fails it will throw an error I believe if an error is throw you can do nothing I believe and you have to handle that on a specific query or you can use the .catch on the query to handle the specific error that gets thrown
mr_pablo
mr_pabloOP17mo ago
But the transactions are all separate, one failing should not cause the ones below it to fail
Noahh
Noahh17mo ago
if it's all within one try/catch like below, then that's just how Type/JavaScript works
try {
await firstTransaction(); // if this throws, it'll jump to the catch block

await secondTransaction(); // never executes because the firstTransaction threw
}catch {
// handle error from either transaction
}
try {
await firstTransaction(); // if this throws, it'll jump to the catch block

await secondTransaction(); // never executes because the firstTransaction threw
}catch {
// handle error from either transaction
}
if you want the errors to be caught but continue executing, you'd want something like this
try {
await firstTransaction(); // if this throws, it'll jump to the catch block
}catch {
// handle error from first transaction
}

try {
await secondTransaction(); // then this would execute
}catch {
// handle error from second transaction
}
try {
await firstTransaction(); // if this throws, it'll jump to the catch block
}catch {
// handle error from first transaction
}

try {
await secondTransaction(); // then this would execute
}catch {
// handle error from second transaction
}
mr_pablo
mr_pabloOP17mo ago
Aha OK! So I need to wrap them in individual try/catch blocks and handle the various errors somehow, gotya
Want results from more Discord servers?
Add your server