Ruby Raise Exception In Initialize

In a nutshell every custom ruby exception should extend standarderror rather than the exception class the reason for this is outlined in exception handling in ruby with this in mind the simplest custom exception class that we can define will look something like this.
Ruby raise exception in initialize. To do exception handling we enclose the code that could raise an exception in a begin end block and use one or more rescue clauses to tell ruby the types of exceptions we want to handle. It is to be noted that the body of a method definition is an implicit begin end block. In ruby like in most languages an exception is a way to convey that something went wrong. If we really need to emphasize oo way in raising exception as you claim i d rather add exception raise i e.
What if you re building a user system and want to raise an exception when the user tries to access an off limits part of the site. Ruby uses the kernel method termed as raise to create the exceptions which will be the instance of exception class or one of its subclass. Ruby s built in exceptions are great but they don t cover every possible use case. We enclose the code that could raise an exception in a begin end block and use rescue clauses to tell ruby the types of exceptions we want to handle.
Rescue clause is used to handle the exceptions created by raise. Syntax begin rescue onetypeofexception rescue anothertypeofexception else other exceptions ensure always will be executed end. While some languages only use exceptions for truly exceptional circumstances like run time errors ruby uses exceptions for a wide variety of errors and unexpected results. None of ruby s standard exceptions fit so your best bet is to create a new kind of exception.
Kernel raise takes either exception class or exception instance.