My program uses a few Option<T>. Using unwrap/expect on the Options panics the program in case of None. Is it okay to let Solana Program panic or should I handle None case by returning error?

1 Answer 1


If your program panics, the transaction will fail and it won't be committed to the Blockchain (Nothing really changes, but you will pay for the fees).

It will definitely be better to return a custom error rather than for the program to panic. You will save a lot of time debugging your code and users who use your code will have a better time understanding what went wrong.

With that being said. In some cases, you want to handle None and maybe run a specific part of the code if that happens rather than failing the transaction. It all depends on your needs.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.