try-catch
@magic-libraries/try-catch
this is the @magic-libraries tryCatch library.
it returns errors instead of throwing them.
installation
npm install @magic-libraries/try-catchusage
tryCatch can wrap any function:
const fn = () => throw new Error('error')const tryCatchable = lib.tryCatch(fn)const result = tryCatchable()// result.message === 'error'
this example contains a Module that uses tryCatch, you can find it here
export const View = () => {const fn = (m) => new Error(m)const catchable = lib.tryCatch(fn)const msg = 'lib.tryCatch returns errors instead of throwing them'const result = catchable(msg)return Pre(result.message)}
renders
lib.tryCatch returns errors instead of throwing themfor another usecase, have a look at @magic-libraries/json
source
the source for this page is in the example directory and gets built and published to github using @magic/core