April 01, 2004 Re: what is try-catch-finally? | ||||
---|---|---|---|---|
| ||||
Karl Bochert wrote: > If complex error handling is needed, I would refactor or do something like: > try { > if (err) { > <pre_cleanup> > throw <myerr> > } > } > catchall { > if (curerr == ioerr) <cleanup_io> > else if (err == myerr ) <cleanup> > else throw <curerr> > } in your example above, for 'try { }', the 'if (err) { }' portion is built in. That's what try { } does, it automatically has a 'if (err) { }'. The code to execute in the 'if (err) { }' is contained in the 'catch (err) { }' block. > Come to think of it, what does 'try' accomplish? I have found that once I got used to the try-catch-finally, it's like cocaine (You can't do without it). It helps you get closer to bullet-proof code. And no, I don't have a drug problem. I just use drugs in my analogies. BA |
Copyright © 1999-2021 by the D Language Foundation