Week 13 - Exception event FPL Flashcards

1
Q

What are exceptions?

A

Exceptions are objects of classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two predefined subclasses of the Throwable class?

A

Error and Exception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When are Error exceptions thrown?

A

Error exceptions are thrown by the runtime system for events such as heap overflow and are never handled by user programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are user-defined exceptions typically subclasses of?

A

User-defined exceptions are typically subclasses of the Exception class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens if no handler is found in the try construct?

A

If no handler is found in the try construct, the search continues in the nearest enclosing try construct. If no handler is found in the method, the exception is propagated to the method’s caller, and if no handler is found all the way to main, the program is terminated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are unchecked exceptions?

A

Unchecked exceptions are those of class Error and RuntimeException and all their descendants. They are not checked by the compiler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is binding exceptions to handlers simpler compared to C++?

A

Binding an exception to a handler is simpler because an exception is bound to the first handler with a parameter of the same class as the thrown object or an ancestor of it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are exceptions thrown?

A

Exceptions are thrown using the throw statement, often combined with the new operator to create the exception object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the finally clause?

A

The finally clause is used to specify code that is executed regardless of whether an exception is thrown in the try construct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What must be done with checked exceptions?

A

Checked exceptions that may be thrown by a method must be either listed in the method’s throws clause or handled within the method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name two predefined subclasses of the Exception class.

A

IOException and RuntimeException are two predefined subclasses of the Exception class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Can a method declare more exceptions in its throws clause than the method it overrides?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the three alternatives for dealing with an exception listed in a called method’s throws clause?

A

1) Catch and handle the exception
2) Catch the exception and throw an exception listed in its own throws clause
3) Declare the exception in its throws clause and do not handle it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens when an assert statement evaluates to false?

A

When an assert statement evaluates to false, an AssertionError exception is thrown.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a key advantage of the throws clause compared to C++?

A

The throws clause provides more information to the programmer by specifying which exceptions a method can throw, unlike the throw clause in C++ which says little.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of the else block in the try-except construct?

A

The else block in the try-except construct is executed if no exceptions are raised in the try block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the assert statement do?

A

The assert statement tests a Boolean expression and raises an AssertionError with an optional message if the expression evaluates to false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How are exception handlers written?

A

Exception handlers are written using the try-except structure, where each except block specifies the type of exception it handles.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How are exceptions raised in another language?

A

Exceptions are raised using the raise statement, which can include an error message.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where are exception handlers placed in another language?

A

Exception handlers are placed at the end of a begin block and are introduced by the rescue keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What unique feature does another language have for handling exceptions that allows code to be rerun?

A

Another language has a retry statement at the end of a handler that allows the code that raised an exception to be rerun.

15
Q

What is an event in the context of event handling?

A

An event is a notification that something specific has occurred, such as a mouse click on a graphical button.

16
Q

What is an event handler?

A

An event handler is a segment of code that is executed in response to an event.

17
Q

What is the purpose of the GUI component library?

A

The GUI component library provides a collection of classes and interfaces for creating GUI components, such as text boxes and radio buttons.

18
Q

What connects events to event handlers?

A

Event listeners connect events to event handlers.

18
Q

What creates events in user interactions with GUI components?

A

User interactions with GUI components create events.

19
Q

How does an event generator inform a listener about an event?

A

An event generator tells a listener of an event by sending a message.

20
Q

How are event generators and listeners connected?

A

Event generators and listeners are connected by event listener registration.

21
Q

What is the role of an interface in event handling?

A

An interface is used to make event handling methods conform to a standard protocol.

22
Q

What must a class that implements a listener also implement?

A

A class that implements a listener must implement an interface for the listener.

23
Q

What user actions are associated with ItemEvent?

A

ItemEvent is associated with the event of clicking a checkbox, a radio button, or a list item.

24
Q

What must be done to handle ItemEvent events?

A

The handler for ItemEvent events should be implemented, and the listener must be registered.

25
Q

Can each event handler receive parameters?

A

Yes

26
Q

What class does RadioB extend, and what interface does it implement?

A

RadioB extends JPanel and implements ItemListener.

27
Q

What does the itemStateChanged method do?

A

The itemStateChanged method determines which button is selected and sets the font accordingly.

28
Q

What are the two approaches to event handling in .NET?

A

The two approaches in .NET are Windows Forms and Windows Presentation Foundation.

29
Q

How is a GUI constructed in Windows Forms?

A

A GUI is constructed using System.Windows.Forms, which implicitly provides a window without the need to build a frame or panel explicitly.

30
Q

How is a radio button’s state tested in C#?

A

A radio button’s state is tested with the Boolean Checked property.

30
Q

How are components positioned in Windows Forms?

A

Components are positioned by assigning a new Point object to the Location property of the component.

31
Q

List some widgets available in tkinter.

A

Some widgets include Button, Canvas, Checkbutton, Entry, Frame, Label, Listbox, Menu, Menubutton, Message, Radiobutton, Scale, Scrollbar, Text, Toplevel, LabelFrame, and PanedWindow.

32
Q

What are some event handler bindings in tkinter?

A

Event handler bindings include <Button-1>, <B1-Motion>, <ButtonRelease-1>, <Double-Button-1>, <Enter>, <Leave>, <FocusIn>, <FocusOut>, <Return>, <Key>, <Shift-Up>, and <Configure>.</Configure></Shift-Up></Key></Return></FocusOut></FocusIn></Leave></Enter></Double-Button-1></ButtonRelease-1></B1-Motion></Button-1>

33
Q

What additional clause does Java include in its exception handling?

A

Java includes a finally clause in its exception handling.

34
Q

What is the primary concern of imperative languages?

A

The primary concern of imperative languages is efficiency rather than suitability for software development.

35
Q

What is an event in programming?

A

An event is a notification that something has occurred that requires handling by an event handler.

35
Q

What is a lambda expression?

A

A lambda expression specifies parameter(s) and mapping functions, such as λ(x) x * x * x.

36
Q

Describe functional composition.

A

Functional composition is a functional form that takes two functions as parameters and yields a function whose value is the first actual parameter function applied to the application of the second, e.g., h(x) ≡ f(g(x)). (exp: f(x) ≡ x + 2 and g(x) ≡ 3x, h ≡ f ̊ g yields (3x) + 2.)

36
Q

What is the apply-to-all functional form?

A

The apply-to-all functional form takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters. (exp: h(x) ≡ x * x, α(h, (2, 3, 4)) yields (4, 9, 16).)

36
Q

Why is it challenging to manage the state changes in large imperative programs?

A

Managing the state changes in large imperative programs is a daunting task due to the importance of variables and how the program’s state changes.

37
Q

What is a higher-order function or functional form?

A

A higher-order function or functional form takes functions as parameters and yields a function as its result or does both.

38
Q

What is referential transparency in FPLs?

A

Referential transparency means the evaluation of a function always produces the same result given the same parameters, making the semantics of FPLs simpler than imperative languages.

39
Q

What are primitive functions in FPLs?

A

Primitive functions are a set of basic functions provided in FPLs, with a smaller number being considered beneficial.