How Does Exception vs Errors | Chris Lattner and Lex Fridman Work?

Imagine you're building a tower with blocks, everything goes smoothly until one block slips and makes the whole tower fall. That’s like errors in programming, they stop things from working as expected.

Now, think of exceptions like a helpful friend who catches that slipping block before it knocks everything down. Instead of the tower falling completely, your friend just says, “Hey, I caught that one,” and you can fix the block without starting over.

Blocks and Bumps

When you're building with blocks:

  • A block slipping is like a regular error, it stops the whole process.
  • A friend catching the block is like using an exception, it lets you keep going, even if something went wrong.

Chris Lattner and Lex Fridman are like two builders who talk about how to handle these slips and catches in their tower-building world (which is actually programming). One uses a simple stop-and-fix method (errors), the other uses a clever catch-and-go strategy (exceptions), both get the job done, just in different ways. Imagine you're building a tower with blocks, everything goes smoothly until one block slips and makes the whole tower fall. That’s like errors in programming, they stop things from working as expected.

Now, think of exceptions like a helpful friend who catches that slipping block before it knocks everything down. Instead of the tower falling completely, your friend just says, “Hey, I caught that one,” and you can fix the block without starting over.

Take the quiz →

Examples

  1. A child drops a glass and it breaks, that’s an error. If the glass was already cracked, that’s an exception.
  2. When you try to open a door but it's locked, that's an error. If the handle is broken, that's an exception.
  3. If you're baking a cake and forget the sugar, that's an error. If the oven breaks during baking, that's an exception.

Ask a question

See also

Discussion

Recent activity