🚨 C++ Runtime Errors

Complete Debugging & Troubleshooting Guide

15+
Error Types Covered
50+
Solutions Provided
10min
Avg. Fix Time

⚡ Quick Jump to Common Errors

💾 Memory-Related Errors

Errors involving memory allocation, access, and management

Segmentation Fault (Core Dumped)

Hard

Program tries to access memory it doesn't own, causing immediate crash.

⏱️ 15-30 min 📊 Very Common

Memory Leak

Medium

Program allocates memory but doesn't free it, causing gradual memory exhaustion.

⏱️ 20-40 min 📊 Common

Double Free or Corruption

Hard

Attempting to free memory that has already been freed.

⏱️ 15-25 min 📊 Moderate

Use After Free

Hard

Accessing memory after it has been deallocated.

⏱️ 20-30 min 📊 Moderate

Buffer Overflow

Hard

Writing data beyond the boundaries of allocated memory.

⏱️ 20-35 min 📊 Common

Heap Corruption

Hard

Corruption of the heap data structure used for dynamic memory.

⏱️ 30-45 min 📊 Rare

📚 Stack-Related Errors

Errors involving the program stack and recursion

Stack Overflow

Medium

Program exceeds available stack space, usually from infinite recursion.

⏱️ 10-20 min 📊 Common

Stack Smashing Detected

Hard

Stack protection mechanism detected buffer overflow on stack.

⏱️ 20-30 min 📊 Moderate

🔢 Arithmetic & Logic Errors

Errors from mathematical operations and logical problems

Floating Point Exception

Easy

Division by zero or invalid floating-point operation.

⏱️ 5-10 min 📊 Common

Integer Overflow

Medium

Arithmetic operation exceeds integer type limits.

⏱️ 10-15 min 📊 Moderate

Assertion Failed

Easy

Program assertion condition evaluated to false.

⏱️ 5-10 min 📊 Common

🖥️ System & Platform Errors

Platform-specific runtime errors and system interactions

Access Violation (Windows)

Medium

Windows-specific memory access violation (0xC0000005).

⏱️ 15-25 min 📊 Common (Windows)

Bus Error (Unix/Linux)

Hard

Misaligned memory access or hardware error on Unix systems.

⏱️ 20-30 min 📊 Rare

Illegal Instruction

Hard

CPU encountered an instruction it cannot execute.

⏱️ 25-40 min 📊 Very Rare

🔧 Essential Debugging Tools

Master these tools to efficiently debug runtime errors

GDB (GNU Debugger)

Step through code, inspect variables, analyze core dumps

gdb ./program core Learn GDB →

Valgrind

Detect memory leaks, buffer overflows, and use-after-free

valgrind --leak-check=full ./program Learn Valgrind →

AddressSanitizer

Fast memory error detector built into GCC/Clang

g++ -fsanitize=address -g program.cpp Learn Sanitizers →

LLDB (macOS)

LLVM debugger for macOS and Xcode development

lldb ./program Learn LLDB →

📋 Quick Reference

Common Causes

  • Null pointer dereference
  • Array index out of bounds
  • Uninitialized variables
  • Memory allocation failures
  • Infinite recursion
  • Race conditions

Prevention Tips

  • Always initialize variables
  • Check pointer validity
  • Use smart pointers (C++11+)
  • Enable compiler warnings
  • Use static analysis tools
  • Write unit tests

Debug Commands

# Generate core dump
ulimit -c unlimited

# Analyze core dump
gdb ./program core

# Memory check
valgrind ./program

# Enable sanitizers
g++ -fsanitize=address,undefined

🔍 Can't Find Your Error?

Or browse our complete troubleshooting guide

📚 Related Resources