There is a code in which every line can cause an exception and I want to continue my execution even if an error occurred in any of the lines of code
I will implement this in the below-mentioned way
begin
code that might throw an exception
rescue
logger
end
begin
code that might throw an exception
rescue
logger
end
begin
code that might throw an exception
rescue
logger
end
begin
code that might throw an exception
rescue
logger
end
is there any better way to handle this type of error handling if yes please explain how can I write better code
every line can cause an exception
please explain how can I write better code
You can write better code by not designing it in such a way that every line can raise an exception. Especially this idea that the code should "plough on ahead, regardless of any trail of errors are left in its wake".
At an extreme, you code could contain all sorts of spelling mistakes / invalid method calls / whatever, and your proposed design would attempt to continue executing the remainder of the code, regardless of how broken it is.
However, I cannot really give concrete advice on how to do this, without seeing some actual code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.