Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

optional way of automatic native exception wrapping

Open
#31 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
android, cpp, javascript, typescript

Research direction

No files, tests, or entry points are named. Start by locating native exception handling in the Android runtime and identifying how runtime options are configured. Done means an optional, disabled-by-default behavior produces a JavaScript Error with the native exception and stack trace when a native exception reaches catch.

Written by the indexing model from the issue text.

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

Dominant language
C++
Stars
33
Forks
3
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NativeScript/napi-android

All issues in NativeScript/napi-android

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.