Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
¿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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda