Closed Chuvi-w closed 3 years ago
This was invalid Ć. The method should have been marked with throws
, like in Java:
public class CanThrow { public static void WillThrow(int a) throws { if (a<15){throw "a<15";} Console.WriteLine(a); } }
I've added the missing error message.
C doesn't support exceptions, so they are emulated by magic return values, here false
for an exception.
Thank you!
void funtion must not return anything.
warning: 'return' with a value, in function returning void [-Wreturn-type]
There were bugs both in your code and cito
. Please pull cito
and rebuild.
C:\0\ci>cat 37.ci
public class CanThrow { public static void WillThrow(int a) { if (a<15){throw "a<15";} Console.WriteLine(a); } }
C:\0\ci>cito -o 37.c 37.ci
37.ci(1): ERROR: 'throw' in a method not marked 'throws'
C:\0\ci>cat 37-fixed.ci
public class CanThrow { public static void WillThrow(int a) throws { if (a<15){throw "a<15";} Console.WriteLine(a); } }
C:\0\ci>cito -o 37-fixed.c 37-fixed.ci
C:\0\ci>cat 37-fixed.c
// Generated automatically with "cito". Do not edit.
#include <stdio.h>
#include <stdlib.h>
#include "37-fixed.h"
struct CanThrow {
};
bool CanThrow_WillThrow(int a)
{
if (a < 15) {
return false;
}
printf("%d\n", a);
return true;
}
C:\0\ci>gcc -c -Wall 37-fixed.c
C:\0\ci>
public class CanThrow { public static void WillThrow(int a) { if (a<15){throw "a<15";} Console.WriteLine(a); } }
compiles into
void CanThrow_WillThrow(int a) { if (a < 15) { return false; } printf("%d\n", a); }