Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed demo
Binary file not shown.
4 changes: 4 additions & 0 deletions exemplos/delegua/falhar-sem-catch.delegua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
escreva("Antes do erro")
falhar "mensagem de erro"
escreva("Depois do erro - não vai aparecer")

8 changes: 8 additions & 0 deletions exemplos/delegua/try-catch-erro.delegua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tente {
falhar "Erro ocorrido"
} pegue (erro) {
escreva(erro)
} finalmente {
escreva("Sempre executa")
}

7 changes: 7 additions & 0 deletions exemplos/delegua/try-catch-simples.delegua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tente {
falhar "Deu erro!"
escreva("Isso não vai aparecer")
} pegue {
escreva("Exceção capturada")
}

6 changes: 6 additions & 0 deletions exemplos/delegua/try-finally.delegua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tente {
escreva("Tentando...")
} finalmente {
escreva("Sempre executa")
}

11 changes: 7 additions & 4 deletions fontes/bibliotecas/padrao.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#include "./padrao.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>

// Utilidades

Expand Down Expand Up @@ -94,4 +90,11 @@ double numero(void *valor) {
char *s = (char*) valor;

return strtod(s, NULL);
}

void falhar(const char *msg) {
size_t tamanho = strlen(msg) + 1;
void* exc = __cxa_allocate_exception(tamanho);
memcpy(exc, msg, tamanho);
__cxa_throw(exc, &_ZTIPc, NULL);
}
23 changes: 22 additions & 1 deletion fontes/bibliotecas/padrao.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

void* __cxa_allocate_exception(size_t thrown_size);
void __cxa_throw(void* thrown_exception, void* tinfo, void (*dest)(void*));
void* __cxa_begin_catch(void* exception_header);
void __cxa_end_catch(void);

extern void* _ZTIPc;

#ifdef __cplusplus
}
#endif

int escreva(const char *fmt, ...);
void *leia(const char *texto, const char *fmt);
int inteiro(void *valor);
double numero(void *valor);
double numero(void *valor);
void falhar(const char *msg);
Loading