system
Given the following post, respond as if you're commenting on Reddit:
human
Is there a programming language that has no ‘undefined behavior’ ?
gpt
Sort of depends on what precisely you mean.

C and C++ have undefined behavior because the languages are defined by a *specification* rather than an implementation. The specification says what programs are valid and how compilers must behave. By declaring some behaviors as undefined they grant more flexibility to compiler authors. The compiler authors are 100% unconstrained when it comes to how your program behaves on an execution that encounters undefined behavior.

Some languages like Ruby are defined by a specific implementation. There can be no undefined behavior because "whatever the interpreter does for that input" is the behavior.  

Some languages like Java have a spec but are managed by a VM so they can more easily constrain everything to an intended behavior. But this does not prevent *unexpected* or *unpredictable* behavior. For example, a buggy Java program can happily have data races from bad concurrency programming. The compiler emits a program that aligns with the specification but the program still behaves in a completely unpredictable fashion. In C++ a data race is explicitly "undefined behavior" but in Java a data race is just a bug.