added replaceAll and replaceFirst as exceptions are not conveniently
propagated to JS context