<div dir="ltr"><div dir="ltr">Broadly speaking, I would say that LLVM is not a good example for projects that want to handle errors with reliability. We tend to have two kinds of errors in compilers:<div>1. Broken invariants</div><div>2. Invalid input</div><div><br></div><div>When LLVM detects broken invariants, it tends to assert or exit with a fatal error. See this long standing guideline: <a href="https://llvm.org/docs/CodingStandards.html#assert-liberally">https://llvm.org/docs/CodingStandards.html#assert-liberally</a> If you are looking for examples of software that is reliable in the face of unforeseen faults, LLVM is not a good example of that. As you mention, OOMs are similarly treated as a fatal error.</div><div><br></div><div>You might still be interested in the elaborate infrastructure for handling relatively common, expected errors of invalid input, missing files, etc. As David mentioned, there's the llvm::Error and Expected classes.</div><div><br></div><div>I'd also point out clang's diagnostic machinery as a common design pattern, where you record errors on some side context, and then propagate failure locally with simple boolean return values. This is, IMO, much more pervasive than Error or error_code, and I personally prefer working with it. This pattern works well when all errors are generally treated the same way, using the same recovery strategies, which is usually the case when attempting to validate input.</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Nov 3, 2018 at 2:08 AM A. Ilchinger via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
as I understand, the LLVM project prohibits the use of exceptions. I<br>
don't want to start a discussion about this decision, but I'd love to<br>
see what alternative error handling is used.<br>
<br>
Could you please point me to some good code examples in the LLVM tree<br>
where one can see how exceptions are avoided? Skimming through the code<br>
I found different approaches (private ctor and create() method with<br>
error return code; using only the ctor and ignoring possible allocation<br>
errors; ...)<br>
Surely, the use of the right error handling strategy is highly<br>
situational, but LLVM also improved over time and without deeper<br>
knowledge of the code base it is impossible for me to see which parts<br>
are "good" and which parts are older and might need refactoring.<br>
<br>
Kind regards<br>
Andreas<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>