in this code, try/catch inside ProcInfo() when using a timer to start or even when using DispatchQueue.global, it crashes when it throws an exception regardless the reason for exception is. Even if 0 information found and then it throws due to that. Got Bad Access error. Had to block out the try/catch, modified the design a bit.
I read your question yesterday and then re-read it today. My conclusion: There’s not enough info here for me to offer any insight. Is this Info structure something you created? If so, why are you using OpaquePointer for a? What’s a actually for?
it crashes when it throws an exception regardless the reason for
exception is.
The word exception is heavily overloaded, and exceptions aren’t the same as errors in Swift. For an explanation of this, see my What is an exception? post on DevForums.
I suspect that you’re triggering a machine exception, which isn’t something you can catch in Swift. And that’s likely because of your use of OpaquePointer, which is an unsafe construct (despite not having Unsafe in the name) and thus can easily trigger machine exceptions.
how to use try/catch block safely in that function so that it would
not crash
It’s hard to answer questions like this without seeing more code — and specifically an explanation for why you’re using OpaquePointer per my previous post — but if this is, as I suspect, a machine exception, there’s no reasonable way to catch that in Swift.
If you post more details about what you’re doing, ideally a small code sample that I can actually compile and run, I should be able to give you better advice.