0
0
Compiler Designknowledge~10 mins

Runtime error handling in Compiler Design - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the type of runtime error.

Compiler Design
try {
    int result = 10 / [1];
} catch (ArithmeticException e) {
    System.out.println("Runtime error: Division by zero");
}
Drag options to blanks, or click blank then click option'
A1
B0
C2
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-zero number does not cause a runtime error.
2fill in blank
medium

Complete the code to catch a null pointer exception at runtime.

Compiler Design
String text = null;
try {
    int length = text.[1]();
} catch (NullPointerException e) {
    System.out.println("Runtime error: Null pointer");
}
Drag options to blanks, or click blank then click option'
AgetLength()
Blength
Csize()
Dlength()
Attempts:
3 left
💡 Hint
Common Mistakes
Using property 'length' without parentheses causes compile error.
3fill in blank
hard

Fix the error in the code to properly handle an array index out of bounds exception.

Compiler Design
int[] numbers = {1, 2, 3};
try {
    int value = numbers[[1]];
} catch (ArrayIndexOutOfBoundsException e) {
    System.out.println("Runtime error: Index out of bounds");
}
Drag options to blanks, or click blank then click option'
A0
B2
C3
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using valid indices does not cause runtime error.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that filters runtime errors by severity.

Compiler Design
errors = {code: desc for code, desc in error_list if code [1] 400 and code [2] 500}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators causes incorrect filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps error codes to descriptions for runtime errors only.

Compiler Design
runtime_errors = { [1]: [2] for [3] in errors.items() if 400 <= [1] < 500}
Drag options to blanks, or click blank then click option'
Acode
Bdesc
Ccode, desc
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names causes runtime errors or syntax errors.