Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
¿Cómo hago aparecer un error de reaccionar nativo?

Tengo un componente funcional donde llamo a un método desde otro archivo .js. El método dentro del archivo .js arroja un error (que está bien, para mis propósitos de prueba), pero quiero que este error llegue al método dentro del componente funcional. ¿Cómo puedo hacer eso?

 import { pickImageAsync, } from "./someFile"; export default class Component1 extends React.Component<any> { render() { const { sendError } = this.props; function pickImage() { try { //calling from another file pickImageAsync(onSend); } catch (error) { //I dont reach this part of the file console.log("I am catching error: ", error); sendImageError(true); } }

En mi archivo someFile.js :

 export async function pickImageAsync(onSend) { if (await getImagePickerPermissionAsync()) { let result; try { //with the way I test it this method throws the error, which I want to bubble up result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, quality: 1, }); //with the way I test it, I dont see any result, which is OK for my testing purposes console.log(result); // I dont reach this peace of code which is fine if (!result.cancelled) { onSend([{ image: result.uri }]); } } catch (error) { //I am catching the error and I see it on the console, but how do I bubble it up? console.log("could not select image: ", error); } } }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Debe throw este error ( throw error ). Esto hará que aparezca en la pila de llamadas hasta que alguien lo atrape (o no, y verá un error en la consola).

Mira la última línea que agregué:

 export async function pickImageAsync(onSend) { if (await getImagePickerPermissionAsync()) { let result; try { //with the way I test it this method throws the error, which I want to bubble up result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.Images, quality: 1, }); //with the way I test it, I dont see any result, which is OK for my testing purposes console.log(result); // I dont reach this peace of code which is fine if (!result.cancelled) { onSend([{ image: result.uri }]); } } catch (error) { //I am catching the error and I see it on the console, but how do I bubble it up? console.log("could not select image: ", error); throw error; } } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda