views:

58

answers:

3
class ApplicationController < ActionController::Base
  class InvalidParam < StandardError;end
end

What is the reason for including another class inside application controller?? What will be the behavior for other controllers?

A: 

Can it be declaration of nested class that will not be used anywhere else?

Karel Frajtak
A: 

The reason for including another class inside application controller is that the class will be visible only inside the controller (scoping). Other controllers will not be influenced.

clyfe
clyfe, class InvalidParam is inheriting StandarError( it is a stub). What will this line of code will do ? why it is written inside application_controller? If you could explain that point it will really help me out.
Vamsi
+1  A: 

Adding Semantics - Private exceptions v System generated exceptions

There's no structural difference between InvalidParam and StandardError - I'm betting that the developer is layering his/her own semantics on InvalidParam. That's naughty because it will just confuse the reader.

The code declares a nested class called InvalidParam for the purposes of Exception handling. The developer wants to be able to raise and rescue exceptions with InvalidParam rather than StandardError - most likely because they want to distinguish between system exceptions and their own.

Chris McCauley