saveSvgAsPng icon indicating copy to clipboard operation
saveSvgAsPng copied to clipboard

How to handle error ?

Open ritwickdey opened this issue 5 years ago • 3 comments

There can be lot of reason for exception. (One example https://github.com/exupero/saveSvgAsPng/issues/199)

But I don't any way to handle error. A typical callback looks like cb(err, data). But in here the callback is cb(data) and if the function throws any error, I can't put any try..catch block as it's a callback operation. (async)

ritwickdey avatar Mar 27 '19 00:03 ritwickdey

I not sure is this related https://github.com/exupero/saveSvgAsPng/pull/205 or not.

ritwickdey avatar Mar 27 '19 00:03 ritwickdey

May be this tag will help

https://github.com/exupero/saveSvgAsPng/commit/79b2e640d424c6e16e18a772094ea1dda88e2ad4?diff=split

ritwickdey avatar Mar 27 '19 00:03 ritwickdey

If the function you're calling returns a promise, you can attach an error-handling callback using the promise's .catch() method. If the function you're calling doesn't return a promise, I'll update it.

exupero avatar Mar 31 '19 13:03 exupero