Exercise: Industrial Reactor Temperature Monitor
Problem statement
You are developing monitoring software for an industrial reactor facility. The system reads temperatures in Celsius from various IoT sensors. Faulty sensors might report physically impossible temperatures below absolute zero (-273.15°C). Additionally, if the reactor temperature exceeds 1000.0°C, it indicates a critical thermal breach. Your utility must evaluate a batch of sensor readings, flag any threshold breaches by throwing the appropriate custom exception, and continue processing the rest of the batch.
Task requirements
Create two custom exception classes:
InvalidTemperatureExceptionandCriticalOverheatingException.Include a property in both exceptions to store the exact faulty temperature reading.
Write a method named
ValidateReadingthat takes a singledoubletemperature.If the reading is above 1000.0°C, throw the
CriticalOverheatingException.If the reading is below -273.15°C, throw the
InvalidTemperatureException.In the top-level entry point, use a
foreachloop to iterate through the array of readings.Place a
try...catch...finallyblock inside the loop to intercept these specific exceptions.Print a distinct alert for each exception type, and ensure a “Sensor check complete.” message logs for every sensor.
Constraints
Inherit both custom exceptions from the standard
ArgumentExceptionclass.Use the
throwkeyword to manually trigger your custom exceptions.Use multiple specific
catchblocks ordered sequentially to target your custom exception types.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
By putting the
try...catchinside theforeachloop, an exception will only skip the rest of the current iteration. This allows the loop to continue to the next temperature reading.Both of your custom exception classes will look structurally identical but have different class names to represent the distinct types of failures.
Make sure your constructors accept both a
string messageand adouble faultyReading. Pass the message parameter to the parent constructor using: base(message).
Exercise: Industrial Reactor Temperature Monitor
Problem statement
You are developing monitoring software for an industrial reactor facility. The system reads temperatures in Celsius from various IoT sensors. Faulty sensors might report physically impossible temperatures below absolute zero (-273.15°C). Additionally, if the reactor temperature exceeds 1000.0°C, it indicates a critical thermal breach. Your utility must evaluate a batch of sensor readings, flag any threshold breaches by throwing the appropriate custom exception, and continue processing the rest of the batch.
Task requirements
Create two custom exception classes:
InvalidTemperatureExceptionandCriticalOverheatingException.Include a property in both exceptions to store the exact faulty temperature reading.
Write a method named
ValidateReadingthat takes a singledoubletemperature.If the reading is above 1000.0°C, throw the
CriticalOverheatingException.If the reading is below -273.15°C, throw the
InvalidTemperatureException.In the top-level entry point, use a
foreachloop to iterate through the array of readings.Place a
try...catch...finallyblock inside the loop to intercept these specific exceptions.Print a distinct alert for each exception type, and ensure a “Sensor check complete.” message logs for every sensor.
Constraints
Inherit both custom exceptions from the standard
ArgumentExceptionclass.Use the
throwkeyword to manually trigger your custom exceptions.Use multiple specific
catchblocks ordered sequentially to target your custom exception types.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
By putting the
try...catchinside theforeachloop, an exception will only skip the rest of the current iteration. This allows the loop to continue to the next temperature reading.Both of your custom exception classes will look structurally identical but have different class names to represent the distinct types of failures.
Make sure your constructors accept both a
string messageand adouble faultyReading. Pass the message parameter to the parent constructor using: base(message).