Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

optional way of automatic native exception wrapping #31

Open
@farfromrefug

Description

Right now in the runtimes when a native exception is thrown which you catch with a try/catch it is the native exception object that you get.
So in my apps/N fork i use something like this:

export function wrapNativeException<T = any>(ex: NSError, wrapError: (...args) => T = (msg) => new Error(msg) as any) {
	if (!ex) {
		return;
	}
	if (typeof ex === 'string') {
		return wrapError(ex);
	}
	if (!(ex instanceof Error)) {
		const err = wrapError(ex.toString());
		err['nativeException'] = ex;
		//@ts-ignore
		err['stackTrace'] = com.tns.NativeScriptException.getStackTraceAsString(ex);
		return err;
	}
	return ex;
}

That method wraps the native exception in a JS error with stackTrace.

Would be pretty awesome to have that done automatically so that the error object you get in catch is an actual JS Error.
I think for now if we can do it it should be optional and disabled by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /